广播接收器接收不到ACTION_BOOT_COMPLETED [英] Broadcast Receiver not receiving ACTION_BOOT_COMPLETED

查看:796
本文介绍了广播接收器接收不到ACTION_BOOT_COMPLETED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试这样做,可以接收ACTION_BOOT_COMPLETED一个基本的广播接收器。每当我在模拟器中运行它,它似乎并不像从广播接收器code中的code。

I'm trying to do a basic BroadcastReceiver that can receive the Action_BOOT_COMPLETED. Whenever I run this in the emulator, it doesn't seem like the code from the BroadcastReceiver code.

清单如下:
    
    

Manifest as follows:

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

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <activity
        android:name=".BootAtStartupActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <receiver
        android:name=".BootAtStartupReceiver"
        android:enabled="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </receiver>
</application>

</manifest>

MainActivity:

MainActivity:

package com.mfcoding.android.bootatstartup;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class BootAtStartupActivity extends Activity {
static final String TAG = "BootAtStartupActivity";

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Log.d(TAG, "onCreate");
}
}

广播接收器:

package com.mfcoding.android.bootatstartup;

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

public class BootAtStartupReceiver extends BroadcastReceiver {
static final String TAG = "BootAtStartupReceiver";

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Log.d(TAG, "*** onReceive ACTION_BOOT_COMPLETED");
    }

    Log.d(TAG, "*** onReceive");
}

}

在logcat中,我从来没有看到该文件的BroadcastReceiver日志打印输出。所有我的logcat看到的是活动日志打印输出。有任何想法吗?
我想在LogCat中看到广播接收器类的日志报表打印。

In Logcat, I never see the Log printout for the BroadcastReceiver file. All i see in Logcat is the Activity log printout. Any ideas? I'd like to see in Logcat the Log print statements of the Broadcast Receiver class.

链接项目
https://github.com/fangstar/BootAtStartup

推荐答案

这是应用程序中出现的第一个设备重新启动该应用程序已安装并运行后至少一次之后,只能接受这个广播意图。
还要注意的是,如果安装在外部存储应用程序可能永远不会收到该广播,因为广播发送后外部存储被安装。

An app can only receive this Broadcast Intent after the first device reboot occurring after the app has been installed and executed at least once. Also note that if the app is installed on external storage it may never receive this broadcast because the external storage gets mounted after the Broadcast has been sent.

这篇关于广播接收器接收不到ACTION_BOOT_COMPLETED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆