拒绝权限:访问服务ComponentInfo {...}从PID = -1权限、ComponentInfo、PID

2023-09-07 17:03:08 作者:坑爹又拼爹的年代i

我试图使用谷歌的行为识别服务。数天前,一切工作就像一个魅力,即我可以连接使用该服务来获取活动信息。但是今天我发现我不能接受任何了。看日志后,我发现这个错误:

I'm attempting to use Google's Activity Recognition Service. Several days ago everything worked like a charm, i.e. I could connect use the service to obtain activity information. But today I found that I couldn't receive any anymore. After looking at the log I found this error:

 05-15 21:19:27.196: W/ActivityManager(765): Permission Denial: Accessing service
 ComponentInfo{edu.umich.si.inteco.captureprobe/edu.umich.si.inteco.captureprobe.
 contextmanager.ActivityRecognitionService} from pid=-1, uid=10220 that is not exported   
 from uid 10223

我重新启动手机,然后重新工作。不过,我重新安装应用程序后,同样的问题又出现了。任何人都可以点出真正的问题会是什么?它说的是有关PID = -1?我有在manifest文件的权限

I rebooted the phone and then it worked again. However, after I reinstall the application, the same problem appeared again. Could anyone point out what the "real" problem would be? Is it something related to "pid=-1"? I do have the permission in the Manifest file

<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION"/>

我找了在谷歌的答案,但大部分的问题是,他们没有把权限清单文件。这似乎只是我一个不同的问题...谁能帮助我?谢谢!

I looked for answers on Google, but most of the issues are that they didn't place permission in the manifest file. This seems to me just a different issue...Could anyone help me? Thanks!

更新:这个问题可以随时通过重新启动手机来解决。然而,当我卸载该应用程序,并重新安装它通过Eclipse中它总是会重新出现。一致的但奇怪的图案(至少对我来说)。我想知道手机是否还记得应用程序,并阻止它后,我卸载它来访问谷歌Play业务(或出于某种原因谷歌播放服务只是不允许我的应用程序来访问它)。任何想法?

UPDATE: The issue can always be solved by rebooting the phone. However, it always reappears when I uninstall the app and reinstall it through Eclipse. A consistent yet weird pattern (at least to me). I'm wondering whether the phone remember the app and stop it to access Google Play service after I uninstall it (or for some reason Google Play service just doesn't allow my app to access it). Any ideas?

推荐答案

我想出了解决方案。究其原因是由于两件事情结合:

I figured out the solution. The reason is due to the combination of two things:

重新安装产生的新的不同的UID同一应用程序的(注意,通过重新安装我的意思卸载从手机上的应用程序,然后使用Eclipse来重新安装)。

Reinstallation generates a new different uid of the same application (note, by reinstallation I meant uninstall the app from the phone and then use Eclipse to reinstall).

默认情况下,在服务标签,出口的值是假的,所描述的here

By default, in the service tag, the value of "exported" is false, as described here

是否的其他应用程序可以调用服务或与它相互作用的组分 - 如果他们可以真和假,如果没有。当该值是假,相同的应用程序或应用程序具有相同的用户ID的唯一组件可以启动服务或绑定到它。默认值取决于服务是否包含意图过滤器。由于没有任何过滤器的装置,它可以通过指定其确切类名称只能被调用。这意味着,该服务仅用于应用程序内部使用(因为其他人不知道的类名称)。因此,在这种情况下,默认值是假。另一方面,至少一个过滤器的presence意味着该服务是用于外部使用,因此缺省值是真。的

所以,我解决我的问题简单地通过设置标志为true。 (谷歌行为识别的样本code使用值假,而不是真实的。)

So I solved my problem simply by setting the flag to "true." (the sample code of Google Activity Recognition use the value "false" instead of "true.")

     <service
        android:name="edu.umich.si.inteco.captureprobe.contextmanager.ActivityRecognitionService"
        android:enabled="true"
        android:exported="true"
        >
    </service>

有趣的是,同样的code适用于Android 4.3或以下。我测试了四个不同的手机不同的Andr​​oid版本我的code和卸载/重新安装问题只发生Android 4.4系统的手机上。所以这就是为什么我被这个问题困惑。为什么没有之前发生?无论如何,如果你遇到了同样的问题(即重新安装后,同样的应用程序无法使用服务),勾选出口标志。

The interesting thing is, the same code works on Android 4.3 or below. I tested my code on four different phones with different Android version, and the uninstallation/reinstallation problem only occurred on the phone of Android 4.4. So that's why the I've been puzzled by the problem. Why didn't it happen before? Anyway, if you run into the same problem (i.e. the same application cannot use a service after you reinstall it), check the "exported" flag.