通知单击未在 Nexus 手机上启动给定的活动 [英] Notification Click not launch the given Activity on Nexus Phones

查看:12
本文介绍了通知单击未在 Nexus 手机上启动给定的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此代码来显示本地通知,当通知出现时,点击通知想要启动 ListActivity 但在 Google nexus 设备上 ListActiviy 不是在点击通知时启动,而是在此代码运行良好的其他设备.

I am using this code to show the local notification and When notification comes then on click of notification want to launch the ListActivity but on Google nexus device ListActiviy is not launches when click on notification, but on other device this code is working well.

    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:

Adding logcat when the activity is not launched:

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)

推荐答案

我上面的代码适用于所有操作系统版本,除了 Kitkat 4.4 和 4.4 +但我有解决方案,我将接收器置于另一个进程中,它适用于所有大多数 Android 操作系统版本......

My above code is working well for all OS version except Kitkat 4.4 and 4.4 + But i have got solution i, put the receiver in another process and it works well for all most Android OS versions...

像这样..

活动 android:name=".NotifyReciever" android:process=":remote"

activity android:name=".NotifyReciever" android:process=":remote"

我们可以在此处了解有关流程的更多信息....

and we can learn more about processes here....

我应该使用 android:process =":remote";在我的接收器中?

这篇关于通知单击未在 Nexus 手机上启动给定的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆