Android BOOT_COMPLETE没有触发(Shell确实)

时间:2015-10-27 14:45:20

标签: java android shell android-intent bootcompleted

我正在尝试在手机启动时启动服务,它可以使用shell命令" adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.example.adrian.wifi / 。接收机"但是当我重新启动手机时没有任何反应。

清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.adrian.wifi" >
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    >
    <service
        android:name=".WiFi"
        android:enabled="true"
        android:exported="true" >
    </service>

    <receiver
        android:name=".Receiver"
        android:enabled="true"
        android:exported="true" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
</application>

接收器:

package com.example.adrian.wifi;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Receiver extends BroadcastReceiver {
private static final String TAG = "com.example.adrian.wifi";
public Receiver() {
}

@Override
public void onReceive(Context context, Intent intent) {
    Log.i(TAG, "Starting");
    Intent myIntent = new Intent(context, WiFi.class);
    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startService(myIntent);
}

}

1 个答案:

答案 0 :(得分:0)

将以下行添加到接收者的意图过滤器:

<category android:name="android.intent.category.DEFAULT" />