【问题标题】:Android BOOT_COMPLETE not triggering (Shell does)Android BOOT_COMPLETE 未触发(Shell 触发)
【发布时间】:2016-01-27 01:03:15
【问题描述】:

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

清单:

<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);
}

}

【问题讨论】:

    标签: java android shell android-intent bootcompleted


    【解决方案1】:

    在接收者的意图过滤器中添加以下行:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多