2
我有一个名为com.example.library的库,其中包含名为com.example.library.http.RestService的服务。库的清单包含以下元素:SecurityException:不允许启动服务Intent without permission
<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上,但是当我尝试在运行2.3.5的HTC Wildfire S上使用它时,尝试启动该服务,但以下情况除外:
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);
我已经冲刷的帮助网页,并在每个读相关的堆栈溢出问题,我可以找到,但只是找不到我想要的东西。
尝试颠倒''和''元素的顺序,在尝试使用它之前定义权限。 –
CommonsWare
@CommonsWare感谢您的建议,但不幸的是没有任何区别。 – Niall
尝试完成上述更改后完全卸载这两个应用程序,然后再次安装它们,看看是否有帮助。 – CommonsWare