2010-04-13 8 views
0

J'ai le code suivant qui crée une notification lorsqu'un message SMS est reçu par le téléphone. Il affiche la notification correctement; Toutefois, lorsque l'utilisateur clique sur la notification, rien ne se passe. Il devrait ouvrir la boîte de réception SMS afin que l'utilisateur puisse voir leur message. Merci d'avance.Android Impossible de lancer la boîte de réception à partir d'une notification

mNotificationManager = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE); 
Uri uri = Uri.parse("content://sms/inbox"); 
PendingIntent contentIntent = PendingIntent.getActivity(arg0, 0, new Intent(Intent.ACTION_VIEW, uri), Intent.FLAG_ACTIVITY_NEW_TASK); 
String tickerText = arg0.getString(R.string.newmsg, msgs[i].getMessageBody().toString()); 
Notification notif = new Notification(R.drawable.icon, tickerText, System.currentTimeMillis()); 
notif.setLatestEventInfo(arg0, msgs[i].getOriginatingAddress(), msgs[i].getMessageBody().toString(), contentIntent); 
notif.vibrate = new long[] { 100, 250, 100, 500 }; 
mNotificationManager.notify(R.string.recv_msg_notif_id, notif); 
+1

N'utilisez pas 'contenu: // sms/inbox'. Cela ne fait pas partie du SDK Android. Votre application va casser sur certains appareils actuels et peut casser dans les futures versions d'Android. – CommonsWare

+0

Vérifiez le code source Android pour voir comment Google fait cela! – MrSnowflake

Répondre

3

Je l'ai eu pour travailler. Le code suivant montre comment accomplir cette tâche:

Intent notificationIntent = new Intent(Intent.ACTION_MAIN); 
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
notificationIntent.setType("vnd.android-dir/mms-sms"); 
Questions connexes