Last active
August 29, 2015 14:05
-
-
Save gohilbhagirath90/cbf865df3316040a3c64 to your computer and use it in GitHub Desktop.
Broadcast Receiver for start android app after booting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Well you can have a BroadcastReceiver declared in your manifest to receive the BOOT_COMPLETED broadcast and then respond to that in your BroadcastReceiver and do what you like. | |
<receiver android:name="MyBootReceiver" | |
android:enabled="true" | |
android:exported="true" | |
android:label="BootReceiver"> | |
<intent-filter> | |
<action android:name="android.intent.action.BOOT_COMPLETED"></action> | |
</intent-filter> | |
</receiver> | |
accepted | |
I've done something similiar, but I was starting activity. Here is how I done it: | |
In Manifest: | |
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> | |
In Java code: | |
public class BootUpReceiver extends BroadcastReceiver { | |
@Override | |
public void onReceive(Context context, Intent intent) { | |
PendingIntent i = PendingIntent.getActivity(context, 0, new Intent( | |
context,MainActivity.class), | |
Intent.FLAG_ACTIVITY_NEW_TASK); | |
AlarmManager mgr = (AlarmManager) context | |
.getSystemService(Context.ALARM_SERVICE); | |
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 20000, i); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment