开发者

Android Unable to launch the Inbox from a notification

开发者 https://www.devze.com 2022-12-27 06:58 出处:网络
I have the following code that creates a notification when an SMS message is received by the phone.It displays the notification correctly; however, when the user clicks the notification, nothing happe

I have the following code that creates a notification when an SMS message is received by the phone. It displays the notification correctly; however, when the user clicks the notification, nothing happens. It should open up the SMS inbox so the user can view their message. Thanks in advance.

mNotificationManager = (NotificationManager) arg0.getSystemService(Context.NOTIFICATION_SERVICE);
Uri uri = Uri.parse("content://sms/inbox");
PendingIntent contentIntent = PendingIntent.getActivity(arg0, 0, new Intent(Intent.ACTIO开发者_如何转开发N_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);


I got it to work. The following code shows how to accomplish this task:

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消