【发布时间】:2013-06-05 11:55:43
【问题描述】:
我有一个名为 com.example.library 的库,其中包含一个名为 com.example.library.http.RestService 的服务。库的清单包含以下元素:
<uses-permission android:name="com.example.library.permission.REST_PERMISSION" />
<permission
android:name="com.example.library.permission.REST_PERMISSION"
android:protectionLevel="signature" />
<application ...>
<service
android:name="com.example.library.http.RestService"
android:enabled="true"
android:permission="com.example.library.permission.REST_PERMISSION"
android:exported="true" >
<intent-filter>
<action android:name="com.example.library.LAUNCH_REST_SERVICE" />
</intent-filter>
</service>
</application>
我在名为 com.example.testapp 的应用程序中使用该库。 TestApp 的清单重复了与上述库完全相同的元素。这在运行 4.0.3 的模拟器和运行 4.2.2 的 nexus 4 上运行良好,但是当我尝试在运行 的 HTC Wildfire S 上使用它时>2.3.5,它在尝试启动服务的那一刻就崩溃了,但以下情况除外:
java.lang.SecurityException: Not allowed to start service Intent
{ act=com.example.library.LAUNCH_REST_SERVICE pkg=com.example.testapp (has extras) }
without permission com.example.library.permission.REST_PERMISSION
我正在使用以下代码启动服务:
Intent intent = new Intent();
intent.setAction( "com.example.library.LAUNCH_REST_SERVICE" );
intent.setPackage( "com.example.testapp" );
[setting some extras]
startService( intent );
我一直在网上寻求帮助,并阅读了我能找到的所有相关 Stack Overflow 问题,但找不到任何我遗漏的东西。
【问题讨论】:
-
尝试颠倒您的
<permission>和<uses-permission>元素的顺序,在尝试使用之前定义权限。 -
@CommonsWare 感谢您的建议,但不幸的是它没有任何区别。
-
在进行上述更改后尝试完全卸载这两个应用程序,然后重新安装它们,看看是否有帮助。
-
@CommonsWare 我可能解释得不好,因为只有 1 个应用程序要删除,它内置了库。我尝试卸载它,但仍然遇到同样的问题。我刚刚在 2.2 模拟器上尝试过,但它启动得很好,所以现在我要尝试将 Wildfire 恢复出厂设置。
-
所以,在它在 2.2 和 2.3 模拟器上运行后,我尝试将 Wildfire S 恢复出厂设置。现在它可以正常工作了。
标签: android android-intent android-manifest android-service android-permissions