androidbroadcastreceiverbootcompleted

android BootCompletedReceiver not fire


I have an android application with this config on Manifest :

    <receiver android:name="ir.hamgam.fion.ec.mobile.services.BootCompletedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>

and in my Receiver i have this :

public class BootCompletedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.w("boot_broadcast_poc", "starting service...");
            APKUpdateReceiver.setAlarm(context);
            DataReceiver.setAlarm(context);
            NotificationUpdateReceiver.setAlarm(context);
        }
    }
}

when application starts and boot completed but not fire inside method onreceive,give me hint please.


Solution

  • Please do as below, it works fine. I put a Toast inside your receiver to be notified about the receiver is called -

    public class BootCompletedReceiver extends BroadcastReceiver {
    
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.w("boot_broadcast_poc", "starting service...");
            Toast.makeText(context, "HElllllooooooo ", Toast.LENGTH_LONG).show();
    //            APKUpdateReceiver.setAlarm(context);
    //            DataReceiver.setAlarm(context);
    //            NotificationUpdateReceiver.setAlarm(context);
            }
        }
    }
    

    Now change the manifest as below -

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.shajib.stackoverflow">
    
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".BootCompletedReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>