Android AlarmManager problem with setting & resetting an alarm

When canceling the AlarmManager do not use a PendingIntent with a flag of FLAG_CANCEL_CURRENT. Instead, cancel the PendingIntent explicitly after canceling the alarm: am = (AlarmManager) getSystemService(getApplicationContext().ALARM_SERVICE); Intent i = new Intent(getApplicationContext(),AlarmReceiver.class); PendingIntent p = PendingIntent.getBroadcast(getApplicationContext(), 0, i, 0); am.cancel(p); p.cancel();

Can’t start activity from BroadcastReceiver on android 10

Android 10’s restriction on background activity starts was announced about six months ago. You can read more about it in the documentation. Use a high-priority notification, with an associated full-screen Intent, instead. See the documentation. This sample app demonstrates this, by using WorkManager to trigger a background event needing to alert the user. There, I … Read more

How does android compare pending intents

To determine if 2 PendingIntents match, the following must be equal: The requestCode parameter used when the PendingIntent was created The Intent ACTION The Intent CATEGORIES The Intent DATA The Intent MIMETYPE The Intent PACKAGE The Intent COMPONENT Extras are not taken into consideration. You can read more in the PendingIntent summary documentation and Intent.filterEquals().

Starting app only if its not currently running

Use a “launch Intent” for your app, like this: PackageManager pm = getPackageManager(); Intent launchIntent = pm.getLaunchIntentForPackage(“your.package.name”); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, launchIntent, 0); Replace “your.package.name” with the name of your package from the Android manifest. Also, you should remove the special launchMode=”singleTask” from your manifest. Standard Android behaviour will do what you want.

Pending intent in notification not working

try this: private void setNotification(String notificationMessage) { //**add this line** int requestID = (int) System.currentTimeMillis(); Uri alarmSound = getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); mNotificationManager = getApplication().getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(getApplicationContext(), NotificationActivity2.class); //**add this line** notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); //**edit this line to put requestID as requestCode** PendingIntent contentIntent = PendingIntent.getActivity(this, requestID,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext()) .setSmallIcon(R.drawable.logo) .setContentTitle(“My … Read more

How to open fragment page, when pressed a notification in android

If you are using Navigation Component you can open a specific destination using NavDeepLinkBuilder: val pendingIntent = NavDeepLinkBuilder(context) .setComponentName(MainActivity::class.java) .setGraph(R.navigation.nav_graph) .setDestination(R.id.destination) .setArguments(bundle) .createPendingIntent() … notificationBuilder.setContentIntent(pendingIntent) … Please note that it’s important to use setComponentName only if your destination isn’t in the launcher activity.

AlarmManager setInexactRepeating, setWindow, setRepeating methods do not fire alarm when called from within loop for week days

try this code its working for Friday Alarm and similarly you can set for Saturday First you have to register your alarm Receiver and alarm time public static void SetAlarmForFriday(Context mContext) { try { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY); System.out.println(“Date ” + calendar.getTime()); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int … Read more