我的广播接收器无法获得BOOT_COMPLETED广播

时间:2015-10-13 12:30:26

标签: android

我安装并打开它,然后重新启动手机,但我的接收器没有收到广播来启动我的服务而没有登录。

我的手机是华硕LF2。

如何在设备启动完成后启动我的服务?

我的接收者

public class BootReceiver extends BroadcastReceiver {

    private final String TAG = getClass().getSimpleName();
    public BootReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG , "Deyu onReceive " + intent.getAction());
        context.startService(new Intent(context, AlarmMessageService.class));
    }
} 

我的清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="go.deyu.dailytodo"
    android:installLocation="internalOnly">

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

    <application
        android:name=".app.App"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            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=".receiver.BootReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </receiver>

        <service
            android:name=".AlarmMessageService"
            android:enabled="true">
        </service>
    </application>

</manifest>

4 个答案:

答案 0 :(得分:3)

我发现为什么手机中的应用程序无法启动完全播放。

我的华硕手机中有一个自动启动管理器设置。

当我允许我的应用程序自动启动时,我的应用程序正常工作....

Ausu LF2 Auto-start Manager

答案 1 :(得分:1)

android:permission="android.permission.RECEIVE_BOOT_COMPLETED"元素中删除<receiver>

答案 2 :(得分:1)

尝试以下代码

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

答案 3 :(得分:0)

Android 3.1或更高版本,如果您想处理android.intent.action.BOOT_COMPLETED broadcastreceiver。您必须注意这一点:

http://developer.android.com/about/versions/android-3.1.html#launchcontrols

1.确保您在安装后打开了应用程序。我认为您已经完成了。

2.检查您的Android移动设备设置:设置 - &gt;应用 - &gt;你的应用 - &gt;强制停止。如果强制停止打开,请关闭它。

3.另一点你要检查是android:name=".receiver.BootReceiver",注意路径,也许系统找不到你的BootReceiver。

相关问题