Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <receiver android:name="com.intapp.receivers.ReminderReceiver"
- android:exported="false"
- android:enabled="true">
- <intent-filter>
- <action android:name="com.intapp.receivers.NOTIFICATION_ALARM" />
- </intent-filter>
- </receiver>
- public static final String ACTION = "com.intapp.receivers.NOTIFICATION_ALARM";
- AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- Intent intent = new Intent(context, ReminderReceiver.class);
- intent.setAction(ACTION);
- int randomNum = new Random().nextInt(Integer.MAX_VALUE - 1 + 1);
- PendingIntent alarmIntent = PendingIntent.getBroadcast(context, randomNum, intent, PendingIntent.FLAG_ONE_SHOT);
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent); // I get time from calendar instance in my function
- } else {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
- } else {
- alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), alarmIntent);
- }
- }
- public class ReminderReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d(TAG, "Receiver called ");
- // my implementation
- }
- }
Add Comment
Please, Sign In to add comment