2013-03-01 5 views

Répondre

0

Il est recommandé d'utiliser Notification.Builder et NotificationCompat.Builder de la bibliothèque de soutien pour les notifications de construction.

Aussi pourquoi utiliser réutiliser le Intent qui a été attrapé par votre BroadcastReceiver? Il devrait se référer à l'activité réelle que vous voulez lancer en cliquant.

Par exemple:

Intent intent = new Intent(context, MainActivity.class); 

Notification notification = new NotificationCompat.Builder(context) 
       .setContentTitle(contentTitle) 
       .setContentText(contentText) 
       .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0)) 
       .setAutoCancel(true) 
       .build(); 

Si vous ne voulez pas vraiment de lancer une activité, vous pouvez commencer un Service ou envoyer un message de diffusion à la place. Voir PendingIntent.

+0

je veux lancer un web, comment je peux le faire ?? – Squall

+0

'Intention intention = new Intent (Intent.ACTION_VIEW, Uri.parse (" http://www.google.com "));' Puis passez-le à 'PendingIntent.getActivity (context, 0, intention, 0) ' –

+0

merci pour l'aide! – Squall

0
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

    Notification notif = new Notification(R.drawable.ic_launcher, "Text", 
      System.currentTimeMillis()); 

    Intent intent = new Intent(this, MainActivity.class); 
    intent.putExtra("somekey", "someextra"); 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 

    notif.setLatestEventInfo(this, "Title", "Message", pIntent); 

    notif.flags |= Notification.FLAG_AUTO_CANCEL; 
    nm.notify(1, notif); 

Utilisez Notification.Builder pour une nouvelle version api

Questions connexes