Posts

Showing posts from April, 2019

Listen to Phone Restarts on Android

When a phone is restarted the system broadcasts ACTION_BOOT_COMPLETED to all the apps that have the RECEIVE_BOOT_COMPLETED permission . In this article, we will learn how to make our app listen to phone restarts. 1) Add permission to the AndroidManifest.xml file. <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> 2) Create a broadcast receiver and add ACTION_BOOT_COMPLETED intent filter to receive the broadcasts. <receiver android:name=".BootCompletedReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> public class BootCompletedReceiver extends BroadcastReceiver { private static final String TAG = BootCompletedReceiver.class.getSimpleName(); @Override public void onReceive(Context context, Intent intent) { if (intent != null && intent.getAction() != null &