-1

I have a simple broadcast receiver that should call a method when a phone is turn on after being powered of or rebooted. but it doesn't receive any calls

  public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
        MainActivity.activateMidnightService(true);
        Log.e("myReceiver", "turned on");
    } 
}
}

and I registered it in the manifest

    <receiver
        android:name="hasebou.karim.simplify.MyReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.ACTION_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
        </intent-filter>
    </receiver> 
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

3

remove

android:permission="android.permission.ACTION_BOOT_COMPLETED" 

from receiver tag and add below line outside application tag.

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Rajen Raiyarela
  • 5,526
  • 4
  • 21
  • 41