2010-07-28 125 views
0

我在應用程序「ServiceDemo」中有一個服務MyService.java。這個應用程序的清單看起來像這樣如何執行遠程服務

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.moto.dev" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".Sample" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <service android:enabled="true" 
       android:name=".MyService" 
       android:permission="syh.permission.STARTMYSERVICE"> 
     </service> 
     </application> 
     <permission 
     android:protectionLevel="normal" 
     android:label="Start My Receiver" 
     android:description="@string/startMyActivityDesc" 
     android:name="syh.permission.STARTMYSERVICE"> 
     </permission> 
    <uses-sdk android:minSdkVersion="8" /> 

</manifest> 

我有另一個應用程序「CallerService」清單看起來像這樣

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="com.moto.dev" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".CallerService" 
        android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

    </application> 

    <uses-permission android:name="syh.permission.STARTMYSERVICE"></uses-permission> 
    <uses-sdk android:minSdkVersion="8" /> 

"src/com/moto/dev/Sample.java"</manifest> 

我從那裏我米試圖上的點擊啓動服務活動按鈕

Intent intent = new Intent(); 
//path where my service is located in application "ServiceDemo" 
intent.setClassName("com.moto.dev","com.moto.dev.MyService"); 
startService(intent); 

這失敗了。說「無法啓動服務意圖」 我可以知道我哪裏出錯了。

回答

0

和我的奇蹟,出現這個SecurityException:不允許啓動服務意圖沒有許可syh.permission.STARTMYSERVICE雖然它已被明確授予!

0

當你的服務沒有意圖過濾器,你將需要設置exported標誌true在服務清單中

相關問題