why receive_boot_completed doesn't work on my device?

混江龙づ霸主 提交于 2019-12-09 20:05:43

问题


i am developing some app need to use receive_boot_completed on rebooting to reset some alarms

it 's working properly on emulator and Samsung tab 2 10.1 .. but it isn't working on my galaxy mini device with android version 2.2.1 !!!

this in my code :

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.engahmedphp.collector"
    android:installLocation="auto"
    android:versionCode="1"
    android:versionName="1.0" >

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"        
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.engahmedphp.collector.SplashActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".PagesActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".FeedsActivity"
            android:configChanges="orientation|keyboardHidden"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".PagePrefsActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".ManagePagesActivity"
            android:launchMode="singleTask"
            android:label="@string/app_name" >
        </activity>        
        <activity
            android:name=".FeedsDialogActivity"
            android:configChanges="orientation|keyboardHidden"
            android:theme="@android:style/Theme.Dialog"
             >
        </activity>        
        <receiver android:name=".FeedsReceiver" >
        </receiver>
        <receiver android:name=".BootCompletedReceiver" 
                  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>

        <service android:name=".GetFeedsService" >
        </service>
        <service android:name=".ResetAlarmsService" >
        </service>
    </application>

</manifest>

BootCompletedReceiver.java

package com.engahmedphp.facebookcollector;

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

import android.util.Log;
import android.widget.Toast;

public class BootCompletedReceiver extends BroadcastReceiver {

    // ==============================================================================

    @Override
    public void onReceive(Context context, Intent intent) {
            Toast.makeText(context, "nice", Toast.LENGTH_LONG).show();
            Log.e("boot", "boot");
            Intent resetAlarms = new Intent(context, ResetAlarmsService.class);
            context.startService(resetAlarms);      

    }

}

回答1:


try to put this line in your receiver's intent-filter.

<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />

If your application is installed on the SD card, you should register this to get the android.intent.action.BOOT_COMPLETED event.

Updated: Since your app is using alarm service, it should not be installed on external storage. Reference: http://developer.android.com/guide/topics/data/install-location.html




回答2:


<receiver android:name="com.yourpacage.BootReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" >
        </action>
    </intent-filter>
</receiver>

try this in manifest



来源:https://stackoverflow.com/questions/19206725/why-receive-boot-completed-doesnt-work-on-my-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!