Je veux utiliser une notification locale dans Android pour ma demande. Si l'application n'est pas ouverte pendant 24 heures qu'une notification locale est envoyée. Quelqu'un peut-il me laisser savoir comment cela devrait être fait? P>
3 Réponses :
Voir: Notifications locales à Android? Vous devriez être capable de planifier une intention avec le responsable d'alarme toutes les heures. P>
Merci pour la réponse rapide, mais peut utiliser Alarm Manager si l'application est fermée. Comment la notification sera-t-elle déclenchée si l'application est fermée?
Oui Gestionnaire d'alarme peut toujours être utilisé même lorsque l'application est fermée. Cependant, vous ne serez pas en mesure de définir un gestionnaire d'alarme lorsque l'application est installée, uniquement lorsque l'application est chargée (au moins une fois) (voir: Stackoverflow .COM / A / 8492846/986105 ). Jetez un coup d'œil à cela pour créer une notification à l'aide de Gestionnaire d'alarme: Smartandroies .blogspot.com / 2010/04 / ...
Si vous souhaitez déclencher une notification locale avec de grandes données, c'est-à-dire avec un texte multiligne en une notification unique avec le titre, le ticker, l'icône, le son .. Utilisez le code suivant. Je pense que cela vous aidera .. STRUT > Intent notificationIntent = new Intent(context,
ReminderListActivity.class);
notificationIntent.putExtra("clicked", "Notification Clicked");
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP); // To open only one activity
// Invoking the default notification service
NotificationManager mNotificationManager;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
context);
Uri uri = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
mBuilder.setContentTitle("Reminder");
mBuilder.setContentText("You have new Reminders.");
mBuilder.setTicker("New Reminder Alert!");
mBuilder.setSmallIcon(R.drawable.clock);
mBuilder.setSound(uri);
mBuilder.setAutoCancel(true);
// Add Big View Specific Configuration
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
String[] events = null;
events[0] = new String("Your first line text ");
events[1] = new String(" Your second line text");
// Sets a title for the Inbox style big view
inboxStyle.setBigContentTitle("You have Reminders:");
// Moves events into the big view
for (int i = 0; i < events.length; i++) {
inboxStyle.addLine(events[i]);
}
mBuilder.setStyle(inboxStyle);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context,
ReminderListActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder
.create(context);
stackBuilder.addParentStack(ReminderListActivity.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder
.getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// notificationID allows you to update the notification later on.
mNotificationManager.notify(999, mBuilder.build());
Intent intent = new Intent(context, yourActivity.class); PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder b = new NotificationCompat.Builder(context); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setWhen(System.currentTimeMillis()) .setSmallIcon(R.drawable.ic_launcher) .setTicker("notification") .setContentTitle("notification") .setContentText("notification") .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND) .setContentIntent(pIntent) .setContentInfo("Info"); NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, b.build());
Je pense que vous devriez créer un service, puis vérifier l'heure, mais pour montrer la notification, vous devez lire à ce sujet. =)
Gorets, vous avez tout à fait raison, je dois utiliser une sorte de service car la notification serait déclenchée lorsque l'application est fermée. Pouvez-vous me fournir un didacticiel pour ça