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