Reputation: 2638
I have boot loader listener. But After user install the application my listener does not start until first boot-up. is there any way to check whether my listener running or not?
Upvotes: 2
Views: 1418
Reputation: 14984
You can't necessarily do exactly what you're wanting, but you could add additional intent filters to your broadcast receiver, ACTION_SCREEN_OFF and ACTION_SCREEN_ON then you are likely to receive some broadcast before the phone is shut off, so your app is able to run after first install before the device is rebooted.
<receiver android:name=".screenOnOffReceiver">
<intent-filter>
<action android:name="android.intent.action.SCREEN_ON" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SCREEN_OFF" />
</intent-filter>
</receiver>
And then the first time your app is run, you could save something to the sharedPreferences such as
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences();
SharedPreferences.Editor editor = pref.edit();
editor.putBoolean("hasRun", true");
editor.commit();
And every time that receiver runs onReceive(...)
it could do the following:
boolean hasRun pref.getBoolean("hasRun", false);
if (!hasRun){
//do code here
}
It's definitely not a guaranteed solution, but it would most likely work.
Upvotes: 0
Reputation: 208002
If you added a receiver for android.intent.action.BOOT_COMPLETED
that will be broadcasted after the boot is completed.
It won't be executed after the application is installed, and there i no method to get your app start automatically after install, the user must explicitly click on it.
Restart your phone and if you get the listener right, it works. To check maybe add some code to the listener, probably should start a Service
or Activity
or raise a Toast
Upvotes: 1