Dans mon application, je vais utiliser ce code pour utiliser la notification:Android: Est-il possible de définir la notification à notifier sur le temps de désir? et même si le projet ne fonctionne pas?
private void addDefaultNotification(){
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon;
CharSequence text = "Notification Text";
CharSequence contentTitle = "Notification Title";
CharSequence contentText = "Sample notification text.";
long when = System.currentTimeMillis();
Intent intent = new Intent(this, NotificationViewer.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
Notification notification = new Notification(icon,text,when);
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
notification.ledARGB = Color.RED;
notification.ledOffMS = 300;
notification.ledOnMS = 300;
notification.defaults |= Notification.DEFAULT_LIGHTS;
//notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
notificationManager.notify(com.example.NotifivcationSample.Constants.NOTIFICATION_ID, notification);
}
RightNow Je reçois le notofication. En appelant cette fonction. Mais je veux, c'est qu'il devrait être informer l'utilisateur, même si l'application ne fonctionne pas à ce moment-là sur l'appareil et la notification devrait être notifier à l'heure désirée.
Est-ce possible? Si oui, alors aidez-moi s'il vous plaît pour cela. Merci.
Modifié:
public class AlarmNotificationReceiver extends BroadcastReceiver{
//private Intent intent;
private NotificationManager notificationManager;
private Notification notification;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
long value1 = intent.getLongExtra("param1", 0);
String value2 = intent.getStringExtra("param2");
addTwoMonthNotification();
}
}
je l'ai fait comme ça, mais pas en mesure de créer une notification dans cette classe de récepteur. Pourquoi ? et que devrais-je faire?
Ok Merci pour la réponse. Laissez-moi essayer. –
Le troisième est la fonction d'utilité? Et si c'est alors où je dois l'appeler? Supposons que si j'utilise toogleButton pour activer/désactiver l'alerm alors devrais-je appeler cette fonction sur "on" à droite? –
Oui, vous devriez l'appeler où vous voulez programmer l'alarme. –