1

サービスを開始および終了しようとしています。私のサービスはログです。

package com.example.textsmslock;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class Logs extends Service
{
    @Override
    public IBinder onBind(Intent arg0){
         // TODO Auto-generated method stub
        return null;
    }
     @Override
        public void onStart(Intent intent, int startId) {
            // TODO Auto-generated method stub
            super.onStart(intent, startId);
            System.out.println("LOGS STARTED");
            Log.d("TAG", "FirstService started");
        }
       @Override
        public void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
        }
}

それを呼び出すアクティビティはConfirmPinです。関数でログが呼び出されています。

// imports...
// public class...

public void ConfirmingPin()
{   
    if(pinCorrect) 
    {
        startService(new Intent("com.example.textsmslock.Logs"));
    }
}

これが私のAndridManifestです

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.textsmslock"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".ConfirmPin"
        android:label="@string/title_activity_confirm_pin" >
        <intent-filter>
            <action android:name="com.example.textsmslock.ConfirmPin" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <service android:name=".Logs"/>
</application>

logcatは言う:

サービスインテントを開始できません{act=com.example.textsmslock.Logs}:見つかりません

私がサービスインテントを開始できない理由を誰かが知っていますか?

4

1 に答える 1

1

アクティビティのマニフェストのIntentFilterが正しくないようです。試してみてください。

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

そして、サービスを開始します。

startService(new Intent(this, Logs.class));

(数分前に別のLogCatでこれを投稿しましたが、そのエラーが私に直接これを示しました。しかし、回答を投稿する前に質問を削除しました...)

于 2012-11-29T18:56:25.797 に答える