Je ne sais pas pourquoi ce code ne fonctionne pas, j'essaie de Service d'arrière-plan comme WhatsApp qui fonctionne pour toujours et vérifie la notification.Service en cours d'exécution en arrière-plan comme WhatsApp
Mais cela ne fonctionne pas, je ne sais pas où je me trompe.
- J'ai ajouté le service dans le manifeste Android
<receiver android:name=".Notifications"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.TIMEZONE_CHANGED" /> <action android:name="android.intent.action.TIME_SET" /> <action android:name="com.application.Notifications" /> </intent-filter> </receiver> <service android:name=".BackgroundWorker"></service>
- J'ai créé trois classes "étend BackgroundWorker IntentService"
`publique BackgroundWorker() { super ("androidservice"); }
@Override
protected void onHandleIntent(Intent intent) {
Log.v("BackgroundWorker:","working");
//user method
createNotification(getApplicationContext(),"BackgroundWorker");
}`
2. classe 'Notifications étend BroadcastReceiver'
@Override
public void onReceive(final Context context, Intent intent) {
Log.d("BroadcastReceiver","onReceive");
Intent t = new Intent(context,BackgroundWorker.class);
context.startService(t);
}
3. J'ai créé troisième classe `longue alertTime = new GregorianCalendar() getTimeInMillis() + 1 * 1000.
Intent notifications = new Intent(this,Notifications.class);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,alertTime,1*1000,PendingIntent.getBroadcast(this,
1,
notifications,
PendingIntent.FLAG_UPDATE_CURRENT));
Log.d("AlarmManager",alarmManager.toString());`
Je ne sais pas où je me trompe.
** Bien que j'ai mis 1 seconde pour Repeatition mais je reçois une notification dans l'intervalle de 5 min **
Et j'ai vérifié le service Android, mon application ne fonctionne pas s'il vous plaît aidez-moi ...
06-16 10:25:21.537 9833-9833/ D/BroadcastReceiver: onReceive 06-16 10:25:21.614 9833-12666/D/BroadcastReceiver: createNotification 06-16 10:30:21.245 9833-9833/ D/BroadcastReceiver: onReceive 06-16 10:30:21.376 9833-15746/r D/BroadcastReceiver: createNotification 06-16 10:35:21.209 9833-9833/ D/BroadcastReceiver: onReceive 06-16 10:35:21.283 9833-18645/ D/BroadcastReceiver: createNotification 06-16 10:40:21.179 9833-9833/ D/BroadcastReceiver: onReceive 06-16 10:40:21.224 9833-21479/ D/BroadcastReceiver: createNotification 06-16 10:45:21.188 9833-9833/ D/BroadcastReceiver: onReceive 06-16 10:45:21.246 9833-24302/ D/BroadcastReceiver: createNotification
avez-vous trouvé une solution –
le problème était Xiaomi Device. Les services sont mieux adaptés à cette fin –