我正在使用这段代码来显示本地通知,当通知出现时,希望在单击通知时启动ListActivity。但是在Google Nexus设备上点击通知时无法启动ListActiviy
,但在其他设备上,此代码可以正常工作。
Intent notificationIntent = new Intent(context,
ListActivity.class);
notificationIntent.putExtra("clicked", "Notification Clicked");
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); // To open only one activity on launch.
PendingIntent pIntent = PendingIntent.getActivity(context, reqCode,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager nM = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder notify = new NotificationCompat.Builder(
context);
notify.setContentIntent(pIntent);
notify.setSmallIcon(R.drawable.app_icon);
notify.setContentTitle("Hello World");
notify.setContentText("");
notify.setAutoCancel(true);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notify.setSound(alarmSound);
notify.setLights(Color.BLUE, 500, 1000);
nM.notify(reqCode, notify.build());
在未启动活动时添加logcat:
03-26 14:22:35.893: W/ActivityManager(515): Permission Denial: starting Intent { cmp=com.x.y/.music.ui.PlaybackActivity bnds=[42,101][636,186] (has extras) } from null (pid=-1, uid=10121) not exported from uid 10126
03-26 14:22:35.893: W/ActivityManager(515): Unable to send startActivity intent
03-26 14:22:35.893: W/ActivityManager(515): java.lang.SecurityException: Permission Denial: starting Intent { cmp=com.x.y/.music.ui.PlaybackActivity bnds=[42,101][636,186] (has extras) } from null (pid=-1, uid=10121) not exported from uid 10126
03-26 14:22:35.893: W/ActivityManager(515): at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1186)
03-26 14:22:35.893: W/ActivityManager(515): at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:741)
03-26 14:22:35.893: W/ActivityManager(515): at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3300)
03-26 14:22:35.893: W/ActivityManager(515): at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:252)
03-26 14:22:35.893: W/ActivityManager(515): at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:192)
03-26 14:22:35.893: W/ActivityManager(515): at android.content.IIntentSender$Stub.onTransact(IIntentSender.java:64)
03-26 14:22:35.893: W/ActivityManager(515): at android.os.Binder.execTransact(Binder.java:404)
03-26 14:22:35.893: W/ActivityManager(515): at dalvik.system.NativeStart.run(Native Method)