1

I researched in order to find out the way to make my app do something on device boot. I tried to do the same but it does not seem to work. I tried with several methods but I am finding some unexpected problems. Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ignacio.dailynotification">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    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>

    <activity
        android:name=".SettingsActivity"
        android:label="@string/title_activity_settings"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

    <receiver
        android:name=".BootCompletedReceiver"
        android:enabled="true"
        android:exported="true"
        android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
</application>

And here is my broadcast receiver BootCompletedReceiver:

public class BootCompletedReceiver extends BroadcastReceiver {
private static final String LOG_TAG = BootCompletedReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {

    String action = intent.getAction();

    String message = "BootCompletedReceiver onReceive, action is " + action;

    Toast.makeText(context, message, Toast.LENGTH_LONG).show();

    Log.d(LOG_TAG, action);

    if(Intent.ACTION_BOOT_COMPLETED.equals(action))
    {
        Toast.makeText(context, "phone restarted",    Toast.LENGTH_SHORT).show();
        Log.d(LOG_TAG,"phone restarted");

    }
}
}

Now I am getting this output in my logcat when searching for 'bootcompleted':

2019-09-20 07:52:56.776 1867-2017/? I/keyguard:     AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:52:57.291 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:52:58.303 1867-2017/? I/keyguard: AsusSlideshowManager:queryLocalList cursor null mBootCompleted:false mRetryQuery:0
2019-09-20 07:53:00.491 1867-1867/? I/keyguard: AsusWeatherDataMonitor: :onBootCompleted
2019-09-20 07:53:16.910 2144-2144/? E/VvmBootCompletedRcvr: phone account ComponentInfo{com.android.phone/com.android.services.telephony.TelephonyConnectionService}, [e0184adedf913b076626646d3f52c3b49c39ad6d], UserHandle{0} has invalid subId -1
2019-09-20 07:53:17.326 1435-2416/? I/ActivityManager: Start proc 4147:com.android.vending/u0a47 for broadcast com.android.vending/com.google.android.finsky.boothandler.BootCompletedReceiver duration: 14
2019-09-20 07:53:19.716 1435-2027/? I/ActivityManager: Start proc    4313:com.asus.dm/1000 for broadcast com.asus.dm/.BootCompletedReceiver duration: 21
2019-09-20 07:53:19.836 4313-4313/? D/DMC->BootCompletedReceiver: ===== BCReceiver: Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check fota update status.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check unfinished dm session.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: check is need resume DL.
2019-09-20 07:53:19.935 4313-4313/? D/DMC->BootCompletedReceiver: ===== over 18 month, no fota polling @receiveBootComplete()
2019-09-20 07:53:19.936 4313-4313/? D/DMC->BootCompletedReceiver: NextPollingInterval: Long.MAX_VALUE
2019-09-20 07:53:19.936 4313-4313/? D/DMC->BootCompletedReceiver: **NOT** Start DM Service
2019-09-20 07:53:19.937 4313-4313/? D/DMC->BootCompletedReceiver: exit onReceive
2019-09-20 07:53:19.938 4313-4313/? I/ActivityThread: Performing receive of Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.asus.dm/.BootCompletedReceiver (has extras) }: app=com.asus.dm.DMApp@a04c4e4, appName=com.asus.dm, pkg=com.asus.dm, comp={com.asus.dm/com.asus.dm.BootCompletedReceiver}, dir=/system/app/DMClient/DMClient.apk, duration=102
2019-09-20 07:53:21.696 4423-4423/? D/FirmwareManager: Booted - onBootCompleted, check for PAD EC and Camera ISP
2019-09-20 07:53:24.792 1435-2706/? I/ActivityManager: Start proc 4686:com.asus.userfeedback/u0a108 for broadcast com.asus.userfeedback/.BootCompletedBroadcastReceiver duration: 18
2019-09-20 07:53:25.721 1435-1435/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1357 android.content.ContextWrapper.startService:620 android.content.ContextWrapper.startService:620 com.dsi.ant.server.AntService.startService:129 com.dsi.ant.server.startup.BootCompletedReceiver.onReceive:41 
2019-09-20 07:53:26.169 1435-2416/? W/BroadcastQueue: Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } to com.google.android.apps.docs/com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver requires android.permission.RECEIVE_BOOT_COMPLETED due to sender null (uid 1000)
2019-09-20 07:53:34.828 5190-5190/? W/GrowthKit: Failed to get GrowthKitJobScheduler in GrowthKitBootCompletedBroadcastReceiver So GrowthKit failed to schedule jobs after package replaced / boot completed.
java.lang.NullPointerException: Unable to get GrowthKit Component from host app.
    at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKit.get(GrowthKit.java:43)
    at com.google.android.libraries.internal.growth.growthkit.inject.GrowthKitBootCompletedBroadcastReceiver.onReceive(GrowthKitBootCompletedBroadcastReceiver.java:29)
    at android.app.ActivityThread.handleReceiver(ActivityThread.java:3044)
    at android.app.ActivityThread.-wrap18(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1561)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:159)
    at android.app.ActivityThread.main(ActivityThread.java:6139)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
2019-09-20 07:53:40.272 2820-5535/? I/constellation: [intent_handler] Received onBootCompleted intent
2019-09-20 07:53:43.700 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: onBootCompleted()
2019-09-20 07:53:43.948 2254-5354/? I/NetRec: [145] BootCompletedOrAppUpdatedIntentOperation.onHandleIntent: Scheduling CleanupDatabaseTask
2019-09-20 07:53:46.769 1435-1453/? I/ActivityManager: Start proc 5946:org.simalliance.openmobileapi.service/1000 for broadcast org.simalliance.openmobileapi.service/.SmartcardServiceBootCompletedBroadcastReceiver duration: 17

I think maybe I am getting the broadcast properly received but my app cannot do anything beyond that or so it seems.

Thanks in advance for your help. Thanks in advance for your help.

Ignacio Garcia
  • 973
  • 9
  • 9
  • check out this ;;;; – Elias Fazel Sep 20 '19 at 00:20
  • Maybe this post can help you : [BroadcastReceiver not receiving BOOT_COMPLETED](https://stackoverflow.com/questions/5051687/broadcastreceiver-not-receiving-boot-completed) – Shim-Sao Sep 20 '19 at 00:37
  • @EliasFazel Thanks for your comment. I tried with that, but it is still not working and I get mostly the same output in the logcat. Permission Denial: receiving Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 (has extras) } .....etc 2019-09-23 09:44:10.780 5663-5663/? W/GrowthKit: Failed to get GrowthKitJobScheduler in GrowthKitBootCompletedBroadcastReceiver So GrowthKit failed to schedule jobs after package replaced / boot completed. java.lang.NullPointerException: Unable to get GrowthKit Component from host app. ......etc – Ignacio Garcia Sep 23 '19 at 00:52
  • Actually I am not even getting any log message from the onReceive function (let alone checking the action's name etc) on boot. I tried as well with the action POWER_DISCONNECTED and I am getting the proper message on disconnecting and connecting the charging cable from the phone. – Ignacio Garcia Sep 23 '19 at 01:14

1 Answers1

-1

check this

   public class BootCompletedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {

            Toast.makeText(context, "phone restarted",    Toast.LENGTH_SHORT).show();
            Log.d(TAG,"phone restarted");

        }
    }
}

ismail
  • 167
  • 1
  • 8
  • thanks for your reply. It is not working though, that is pretty much the same I have. Could you show me what would I need for the Manifest, etc other problems that could be keeping my phone from receiving the BOOT_COMPLETED broadcast? Thanks in advance. – Ignacio Garcia Sep 23 '19 at 01:25
  • I think you just need this ` ` – ismail Sep 23 '19 at 08:43
  • Thanks for that, it is a simplified version of what I had. But it does not work either. – Ignacio Garcia Sep 24 '19 at 22:38