Guest User

Untitled

a guest
Oct 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <receiver android:name="com.intapp.receivers.ReminderReceiver"
  2. android:exported="false"
  3. android:enabled="true">
  4. <intent-filter>
  5. <action android:name="com.intapp.receivers.NOTIFICATION_ALARM" />
  6. </intent-filter>
  7. </receiver>
  8.  
  9. public static final String ACTION = "com.intapp.receivers.NOTIFICATION_ALARM";
  10.  
  11. AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
  12. Intent intent = new Intent(context, ReminderReceiver.class);
  13. intent.setAction(ACTION);
  14. int randomNum = new Random().nextInt(Integer.MAX_VALUE - 1 + 1);
  15. PendingIntent alarmIntent = PendingIntent.getBroadcast(context, randomNum, intent, PendingIntent.FLAG_ONE_SHOT);
  16. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  17. alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); // I get time from calendar instance in my function
  18. } else {
  19. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  20. alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
  21. } else {
  22. alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
  23. }
  24. }
  25.  
  26. public class ReminderReceiver extends BroadcastReceiver {
  27. @Override
  28. public void onReceive(Context context, Intent intent) {
  29. Log.d(TAG, "Receiver called ");
  30. // my implementation
  31. }
  32. }
Add Comment
Please, Sign In to add comment