Runtime exception Android O with boot_completed

Here are some options that I outlined in a blog post: Workaround #1: startForegroundService() Your BroadcastReceiver that receives the ACTION_BOOT_COMPLETED broadcast could call startForegroundService() instead of startService() when on Android 8.0+: import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Build; public class OnBootReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Intent i=new … Read more

Alarm Manager does not work in background on Android 6.0

There are a couple of things you can try which, when used in concert, should be able to cut through all of the idle/standby/doze modes (irrespective of OS version). 1. Use a WakefulBroadcastReceiver instead of an ordinary BroadcastReceiver. Make sure you include the WAKE_LOCK permission to use it correctly. 2. Use the setExactAndAllowWhileIdle() method (on … Read more

Oreo BroadcastReceiver SMS Received not working

Previously I was requesting for -Manifest.permission.READ_SMS which didn’t worked then I changed the permissions to – Manifest.permission.RECEIVE_SMS then it started working in oreo and I also specified the receiver in manifest I don’t know whether that helped or not but this made the day for me public static void requestPermissionForReadSMS(Fragment fragment) { // if (fragment.shouldShowRequestPermissionRationale(Manifest.permission.READ_SMS)) … Read more

Boot BroadcastReceiver does not work on Xiaomi devices

I searched around the web and found a solution, I’ve decided to answer my own question. Follow the same code given in the question. In Xiaomi devices, you just have to add your app to Autostart list, to do so, follow these simple steps given below: Open Security app on your phone. Tap on Permissions, … Read more

CONNECTIVITY_ACTION intent received twice when Wifi connected

NOTE: For a recent, up-to-date answer, see this one below! After a lot of googling and debugging, I believe this is the correct way to determine if Wifi has connected or disconnected. The onReceive() method in the BroadcastReceiver: public void onReceive(final Context context, final Intent intent) { if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)) { NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO); if(networkInfo.isConnected()) { … Read more

Broadcast Receiver Not Working After Device Reboot in Android

Here’s a tested and working solution on both the devices that you mentioned, OnePlus and Mi. As you said the auto-start prevention feature on OnePlus and Mi devices prevent apps from starting up their services automatically on boot complete so as to improve the overall device boot speed and battery performance. However, there’s a workaround … Read more

Intent Action for Download Completion not visible in AndroidManifest.xml

You can do like this. DownloadManager downloadManager; downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE); Uri uri = Uri.parse(“http://xxx.apk”); DownloadManager.Request request = new DownloadManager.Request(uri); // You can choose network type request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI); downloadManager.getRecommendedMaxBytesOverMobile(getApplicationContext()); final long flag = downloadManager.enqueue(request); IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE ); BroadcastReceiver receiver = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent) { long anotherFlag = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID,-1); … Read more