Reputation: 23
my notification is not working on API 23.
My Notfication works succesfull from API 16 to 22
The 100 for calstd/calmin is a default number.
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
if(calstd==100||calmin==100){
cancelAlarm();
}
else {
onTimeSet(calstd, calmin);
}
pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, mainsite.class), 0);
nm1 = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notif = new Notification.Builder(context);
uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notif.setContentTitle("Remind Me");
notif.setContentText("Vergiss deine Pille nicht :)");
notif.setSmallIcon(R.drawable.ic_launcher);
notif.setSound(uri);
notif.setAutoCancel(true);
notif.setContentIntent(pendingIntent);
nm1.notify(15, notif.build());
...
}
public void setAlarm(Calendar targetCal) {
intent = new Intent(contexta, AlarmReceiver.class);
pendingIntent = PendingIntent.getBroadcast(contexta, RQS_1, intent, 0);
alarmManager = (AlarmManager) contexta.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= 19)
alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
else if (Build.VERSION.SDK_INT >= 16)
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), 1 * 1000 * 60 * 60 * 24, pendingIntent);
}
Manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:process=":remote" android:name=".Alarm"/>
<receiver android:name="com.victoriaremindme.AlarmReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Its not working after closing the Apps. I cant find the Problem.
Upvotes: 2
Views: 2488
Reputation:
The difference with 23 is runtime permissions. You need to review your app for dangerous permissions. As the new api means the app will not run many task if runtime permissions are not managed, but will either silently ignore the code that requires the permission, or crash.
Requesting Permissions at Run Time
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
Normal and Dangerous Permissions
Normal permissions cover areas where your app needs to access data or resources outside the app's sandbox, but where there's very little risk to the user's privacy or the operation of other apps. For example, permission to set the time zone is a normal permission. If an app declares that it needs a normal permission, the system automatically grants the permission to the app. For a full listing of the current normal permissions, see Normal permissions.
Dangerous permissions cover areas where the app wants data or resources that involve the user's private information, or could potentially affect the user's stored data or the operation of other apps. For example, the ability to read the user's contacts is a dangerous permission. If an app declares that it needs a dangerous permission, the user has to explicitly grant the permission to the app.
Table 1. Dangerous permissions and permission groups.
Upvotes: 1
Reputation: 7070
For API 23
and above you can use setAndAllowWhileIdle()
So change your code to
if (Build.VERSION.SDK_INT >= 23)
alarmManager. setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
else if (Build.VERSION.SDK_INT >= 19)
alarmManager.setExact(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
else if (Build.VERSION.SDK_INT >= 16)
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), 1 * 1000 * 60 * 60 * 24, pendingIntent);
Check the documentation here.
Hope this helps.
Upvotes: 2