1

デバイスのウェイクアップに応答するためのWakefulBroadcastReceiverという v4 ヘルパー クラスについて知っています。

デバイスが起動したことを単純に検出し、必要なロジックを実行するヘッドレス Android アプリを作成したいと考えています (以下のテスト アプリでは、メッセージをログに記録するだけです)。

ただし、アプリのマニフェストで指定するインテントを見つけることができなかったため、WakefulBroadcastReceiverが起動されます。

WakefulBroadcastReceiverがデバイスのウェイクアップのすべてのインスタンスを検出するように、そのようなアプリを構成する方法を知っている人はいますか?

まず、WakefulBroadcastReceiverは次のとおりです。

public class MyWakeupReceiver extends WakefulBroadcastReceiver {

    public void onReceive(Context context, Intent intent) {

        Log.i("MyWakeupReceiver", "received wake-up intent: " + intent.toString());

        startWakefulService(context, new Intent(context, MyWakeupService.class));
    }
}

...そして、実行されるサービスは次のとおりです。

public class MyWakeupService extends IntentService {

    public MyWakeupService() {
        super("MyWakeupService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        Log.i("MyWakeupService", "onHandleIntent: " + intent.toString());

        // Do stuff here.

        MyWakeupReceiver.completeWakefulIntent(intent);        
    }

}

最後に、これが私のマニフェストです。「何がここにあるのか????」に注意してください。インテント フィルターで。

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

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver android:name="my.test.package.MyWakeupReceiver" android:enabled="true" android:exported="false">

            <intent-filter>
                <action android:name="android.intent.action.WHAT_GOES_HERE????" />
            </intent-filter>

        </receiver>

        <service android:name="my.test.package.MyWakeupService" />

    </application>

</manifest>

どうもありがとうございました。

4

1 に答える 1

1

この質問はほぼ 1 年前のものですが、これを理解したことがありますか? インテント フィルター ビットで必要なアクションはandroid.intent.action.SCREEN_ONandroid.intent.action.SCREEN_Off. 私は似たようなことをしようとしていますが、何らかの不思議な理由でそれらのアクションをマニフェストに登録できないことを発見しました。

于 2015-01-31T04:43:53.033 に答える