权限拒绝:从null(pid = -1,uid = 10221)启动Intent不从uid导出

时间:2015-05-05 21:37:23

标签: android android-intent

我有这种情况:

服务正在运行。该服务具有定时器,该定时器定期对服务器进行http调用以搜索数据。该数据已由其他用户存储在DB中。当该数据可用时,将解析来自服务器的答案,并显示通知。当用户点击通知时,将启动活动...直到昨天。我正在使用Eclipse,一个用于接收数据的用户的真实设备,以及一个用于发送数据的用户的虚拟设备。

当用户点击通知时,活动没有启动,这有点奇怪,因为它一直工作到昨天,正如我所说。在Logcat我有这个:

05-05 23:12:36.841: W/ActivityManager(1029): Permission Denial: starting Intent { cmp=my.package/.CalledFromNotificationActivity bnds=[0,538][540,632] (has extras) } from null (pid=-1, uid=10221) not exported from uid 10242
05-05 23:12:36.851: W/ActivityManager(1029): Unable to send startActivity intent
05-05 23:12:36.851: W/ActivityManager(1029): java.lang.SecurityException: Permission Denial: starting Intent { cmp=my.package/.CalledFromNotificationActivity bnds=[0,538][540,632] (has extras) } from null (pid=-1, uid=10221) not exported from uid 10242
05-05 23:12:36.851: W/ActivityManager(1029):    at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1215)
05-05 23:12:36.851: W/ActivityManager(1029):    at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:747)
05-05 23:12:36.851: W/ActivityManager(1029):    at com.android.server.am.ActivityManagerService.startActivityInPackage(ActivityManagerService.java:3372)
05-05 23:12:36.851: W/ActivityManager(1029):    at com.android.server.am.PendingIntentRecord.sendInner(PendingIntentRecord.java:252)
05-05 23:12:36.851: W/ActivityManager(1029):    at com.android.server.am.PendingIntentRecord.send(PendingIntentRecord.java:192)
05-05 23:12:36.851: W/ActivityManager(1029):    at android.content.IIntentSender$Stub.onTransact(IIntentSender.java:64)
05-05 23:12:36.851: W/ActivityManager(1029):    at android.os.Binder.execTransact(Binder.java:404)
05-05 23:12:36.851: W/ActivityManager(1029):    at dalvik.system.NativeStart.run(Native Method)

这是启动Intent的代码:

Intent intent=new Intent(c, CalledFromNotificationActivity.class);
Bundle bundle=new bundle();
bundle.setString("somedata", somedata);
intent.putExtras(bundle);
PendingIntent pIntent=PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);                           
                        Builder notif = new NotificationCompat.Builder(c);
                        synchronized (notif) {

                                    notif.setContentIntent(pIntent)
                                            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                                            .setWhen(System.currentTimeMillis())
                                            .setTicker("Notification ticker")
                                            .setSmallIcon(R.drawable.ic_launcher)
                                            .setContentTitle(getString(R.string.app_name))
                                            .setContentText(getString(R.string.text))
                                            .setAutoCancel(true);

                                    Notification notification = notif.build();
                                      //get instance of NotificationManager
                                      NotificationManager notificationmanager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                                      notificationmanager.notify(0, notification);
                                     timer.cancel();
                            }

我已经读过在Manifest文件的Activity声明中添加android:exported="true"可以解决它,但我不愿意使用它,因为在我的情况下显然不是预期用途。

我认为它可能是pid中的-1 ...但我不知道为什么是-1以及如何解决它。

有人可以帮我吗?

谢谢。

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,这是Kitkat的问题,我从here获得了workround解决方案。你可以这样试试:

PendingIntent pIntent = PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);  
        if (Build.VERSION.SDK_INT == 19) {
            contentIntent.cancel();
            pIntent = PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        }

它对我有用,希望有用。