2012-02-05 78 views
0

我試圖從一個活動調用服務:不允許啓動服務意向

當我運行程序的活動會拋出它說的錯誤:不允許啓動服務的意圖。我究竟做錯了什麼?我很抱歉代碼中可能存在的愚蠢錯誤,但我是一個新手。

活動代碼:

public void startService() { 
try { 
startService (new Intent (this , SmsReminderService.class)) ; } 
catch (Exception e) { Log.v("Error" , e.getMessage()) } 
} 

服務代碼:

public class SmsReminderService extends Service { 

@Override 
public void onStart(Intent intent, int startid) { 
    Log.v("SSms", "Service started") ; }} 

清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="me.sms.smsReminder" 
android:versionCode="1" 
android:versionName="1.0" > 

<uses-sdk android:minSdkVersion="10" /> 

<permission android:name="SEND_SMS"></permission> 


<application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 
    <activity 
     android:label="@string/app_name" 
     android:name=".SmsReminderActivity" > 
     <intent-filter > 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <service android:name=".SmsReminderService"  
      android:permission="android.permission.BIND_REMOTEVIEWS"> 
      <intent-filter> 
       <action android:name = "android.intent.category.LAUNCHER" ></action> 
      </intent-filter> 

     </service> 
</application> 
</manifest> 

在此先感謝,湯姆

回答

1

爲什麼這樣的服務?

<intent-filter> 
    <action android:name = "android.intent.category.LAUNCHER" ></action> 
</intent-filter> 

嘗試添加此:

<uses-permission android:name="android.permission.BIND_REMOTEVIEWS" /> 
+0

感謝您的回答。它現在工作:) – tb96 2012-02-05 20:51:37