Tutorials Android How to Start an Application at Device Bootup in Android

How to Start an Application at Device Bootup in Android

This tutorial will explain to stat an application while the Android device boot-up. For this we need to  listen to the BOOT_COMPLETED action and react to it. BOOT_COMPLETED is a Broadcast Action that is broadcast once, after the system has finished booting. You can listen to this action by creating a BroadcastReceiver that then starts your launch Activity when it receives an intent with the BOOT_COMPLETED action.

1. Add this permission to your manifest:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

How to Start an Application at Device Bootup in Android

2. Create a Custom BroadcastReceiver in your project to receive boot up event

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class BootReceiver extends BroadcastReceiver{

	@Override
	public void onReceive(Context context, Intent intent) {
		Intent i = new Intent(context, MainActivity.class);  
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);  
	}
}

3. Adding the BroadCastReceiver to the Android Manifest

<receiver
android:name=".BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

Install the application, and then restart the device. You can see the application will start after the device restarts.

Total
0
Shares
guest
9 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Federico Capece
Federico Capece
7 years ago

This helped me a lot, thanks

TominoCZ
TominoCZ
7 years ago

I’ve been looking for this for over a month and I finally found a working solution!
Thanks to whoever made this tutorial!

gretar
gretar
6 years ago

This was awesome. Those two lines were missing and driving me crazy! Thanks a lot!!!

android:enabled=”true”
android:permission=”android.permission.RECEIVE_BOOT_COMPLETED”

Danish
Danish
6 years ago

Hii guys please check my code i have been trying to run but boot receiver is not responding how ever i try

My Boot Receiver

public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(“android.intent.action.BOOT_COMPLETED”)) {
Intent i = new Intent();
i.setClassName(“com.talentcodeworks.callrecorder”, “com.talentcodeworks.callrecorder.callrecorder”);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
Toast.makeText(context,”BOOT”,Toast.LENGTH_SHORT).show();
}
}
}

I cannot figure it out why is this not working on my vivo android version 5.0

Fruxinfo Private Limited
Fruxinfo Private Limited
5 years ago

but that function not working Redmi Note 3
how can sol

Nilanchala Panigrahy
Nilanchala Panigrahy
5 years ago

You getting any error on console?

Pritesh Patel
Pritesh Patel
5 years ago

i used complete code in android studio .. but after restarting application nothing happen…

Vishal Bhimporwala
Vishal Bhimporwala
4 years ago
Reply to  Pritesh Patel

Refer this solution – Give the permission from settings.: https://stackoverflow.com/a/36172099/8078641

Osamah Taher
Osamah Taher
4 years ago

Actually it’s great and I would to thank the programmer. Only one thing why it’s starting up very slow.

Previous Post

TextSwitcher and ImageSwitcher Example in Android

Next Post
Sencha Touch Tutorials

Creating “Hello World!” Using Sencha Touch

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
9
0
Would love your thoughts, please comment.x
()
x