不允许启动服务Intent

时间:2012-02-05 18:30:05

标签: android

我正在尝试从活动中调用服务:

当我运行该程序时,该活动会抛出一个错误,指出:不允许启动服务Intent。我究竟做错了什么?我很抱歉代码中可能存在愚蠢的错误,但我是新手。

活动代码:

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 个答案:

答案 0 :(得分:1)

为什么要在服务中使用?

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

尝试添加此内容:

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