I want to create an Android application which performs some action periodically (every minute) in the background. The application shall have no user interface, therefore there will be no Action-Class. It shall start automatially after boot.
I have coded my Application as shown below, but it just does not start after boot? Can anyone help?
I am using a Samsung Tablet GT-P5200 with Android 4.4.2
Many thanks for your help in advance.
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.somecompany.justoneservice" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
<service
android:name=".MyService"
android:enabled="true"
android:exported="true" >
</service>
</application>
</manifest>
BootReceiver.java
package com.somecompany.justoneservice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.text.format.DateUtils;
import android.util.Log;
public class BootReceiver extends BroadcastReceiver {
public BootReceiver() {
}
#Override
public void onReceive(Context context, Intent intent) {
Log.d("TAG", "BOOT");
long interval = DateUtils.MINUTE_IN_MILLIS * 1;
long firstStart = System.currentTimeMillis() + interval;
Intent mainServiceIntent = new Intent(context, MyService.class);
PendingIntent mainServicePendingIntent = PendingIntent.getService(context, 0, mainServiceIntent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setInexactRepeating(AlarmManager.RTC, firstStart, interval, mainServicePendingIntent);
}
}
MySevice.java
package com.somecompany.justoneservice;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class MyService extends Service {
public MyService() {
}
#Override
public void onCreate() {
super.onCreate();
Log.d("TAG", "Service created.");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("TAG", "Service started. (" + startId + ")");
return super.onStartCommand(intent, flags, startId);
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.d("TAG", "Service started.");
}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
The application shall have no user interface, therefore there will be no Action-Class.
Newly-installed apps' manifest-registered receivers are disabled until something uses an explicit Intent to start one of your components. Usually, this is the user tapping on the icon for one of your activities in a home screen's launcher. And usually that is not a problem, because all apps need an activity, to allow the user to configure the behavior of the app, get help, read the license agreement terms, etc.
In some scenarios, something other than a home screen launcher icon can start up one of your components with an explicit Intent. For example, if you are a plugin to some other app, that other app might detect your installation and start up one of your components.
But, if nothing will start one of your components with an explicit Intent, then your BOOT_COMPLETED receiver will never get control, even after a reboot.
Related
I am trying to create a Service application without a UI/Activity.
The service will start on BOOT_COMPLETED. Currently I am experiencing an issue when the receiver service cannot start the main service.
The error sound like that (Android Device Monitor):
Tag: Activity Manager
Text: Unable to start service Intent { cmp=com.remote.cat/.ActionService } U=0: not found
My android OS version on the device is 4.2.2
I am testing it via this command in PowerShell:
adb.exe shell am broadcast -a android.intent.action.BOOT_COMPLETED -n com.remote.cat/.AutoStartServiceReceiver
Both services are in the root of the package com.remote.cat
Feel like I am missing a small thing or having a typo, would greatly appreciate any help!
Thank you!
Here is the code of the manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.remote.cat"
android:installLocation="internalOnly">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true" android:label="#string/app_name"
android:icon="#mipmap/ic_launcher" android:theme="#style/AppTheme">
<receiver android:name="com.remote.cat.AutoStartServiceReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
<service android:name="com.remote.cat.AutoStartServiceReceiver"></service>
<service android:name="com.remote.cat.ActionService"></service>
</manifest>
Here is the brodcastreceiver class:
package com.remote.cat;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class AutoStartServiceReceiver extends BroadcastReceiver
{
#Override
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent serviceIntent = new Intent(context, ActionService.class);
//Intent serviceIntent = new Intent("com.remote.cat.ActionService");
context.startService(serviceIntent);
}
}
}
Here is the main service that I am trying to start:
package com.remote.cat;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class ActionService extends Service
{
private ScheduledThreadPoolExecutor executor = null;
#Override
public IBinder onBind(Intent intent)
{
return null;
}
#Override
public int onStartCommand(Intent intent, int flags, int startId)
{
executor = new ScheduledThreadPoolExecutor(4);
final ScheduledFuture<?> handle = executor.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
Toast.makeText(getApplicationContext(), "one minute message", Toast.LENGTH_LONG).show();
}
}, 0, 8, TimeUnit.SECONDS);
return START_STICKY;
}
}
Change your AutoStartServiceReceiver declaration in the manifest to be a <receiver> rather than <service>.
The error is in your broadcastreceiver class
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED))
it should be
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
EDIT
I believe you have to declare your services inside the application tag since it is a part of the application
I have stuck with an issue of running a service when force stop is clicked and when i restart my mobile the service should be invoked.I have followed some examples but i cant able to achieve the task.Can any one guide me to achieve the task.
Required:
1.Service should run when force stop has been clicked from settings
2.Service should run when mobile has been restarted.
TestActivity.java
package com.testsearching;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class TestActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
startService(new Intent(this, ServiceTest.class));
}
}
ServiceTest.java
package com.testsearching;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class ServiceTest extends Service {
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
mTimer = new Timer();
mTimer.schedule(timerTask, 2000, 2 * 1000);
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
} catch (Exception e) {
e.printStackTrace();
}
return super.onStartCommand(intent, flags, startId);
}
private Timer mTimer;
TimerTask timerTask = new TimerTask() {
#Override
public void run() {
Log.e("Log", "Running");
}
};
public void onDestroy() {
try {
mTimer.cancel();
timerTask.cancel();
} catch (Exception e) {
e.printStackTrace();
}
Intent intent = new Intent("com.android.techtrainner");
intent.putExtra("yourvalue", "torestore");
sendBroadcast(intent);
}
}
ReceiverCall.java
package com.testsearching;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
public class ReceiverCall extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Log.i("Service Stops", "Ohhhhhhh");
context.startService(new Intent(context, ServiceTest.class));;
Toast.makeText(context, "My start", Toast.LENGTH_LONG).show();
}
}
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testsearching"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:allowBackup="true"
android:theme="#style/AppTheme" >
<activity
android:name="com.testsearching.TestActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".ServiceTest" >
<intent-filter>
<action android:name="com.testsearching.ServiceTest" />
</intent-filter>
</service>
<receiver
android:name="ReceiverCall"
android:enabled="true"
android:exported="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED" >
<intent-filter>
<action android:name="com.android.techtrainner" />
<action android:name="android.intent.action.SCREEN_ON" />
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
</manifest>
In theory, this is not possible; according to the Android security model.
As Panaj Kumar points out in the comments:
When user does force stop, means he does not want to run this
application (any component). he is not interested anymore, and this
is rights of user. SO android does not gives a way to keep running
your service, even after forced close your app.
Android will prevent the app from restarting using the START_STICKY flag, and will disable the RECEIVE_BOOT_COMPLETED receiver. The system will also disable all Alarms that have been set for this app.
Before the system will allow the app to run again, the user must run an Activity of the app themselves.
That said, it seems that certain apps are still able to break the rules in this way. This should be considered incorrect and would be taking advantage of a security hole, however it shows that it is still possible, even on KitKat.
The Discovery Insure driving app seems to be able to restart itself when it has been force stopped, and will restart on boot:
Discovery Insure Driving Challenge on Play Store
However, this functionality should not be relied on - hopefully this security flaw will be fixed in future system updates.
Write this on in your OnCreate of the main launching activity
if(!isMyServiceRunning(ServiceClass.class))
context.startService(new Intent(context.getApplicationContext(),ServiceClass.class));
here is the running service check function
private boolean isMyServiceRunning(Class<?> serviceClass) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (serviceClass.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}
and Create your service with this architecture.Observe the return START_STICKY
public class ServiceClass extends IntentService {
public ServiceClass()
{
super("null");
}
public Context context;
public Intent intent;
public Date currentTime;
#Override
public int onStartCommand(#Nullable Intent intent, int flags, int startId) {
onHandleIntent(intent);
return START_STICKY;
}
#Override
protected void onHandleIntent(#Nullable Intent intnt) {
currentTime = Calendar.getInstance().getTime();
context = getApplicationContext();
this.intent = intnt;
Log.d("ServiceClass","Service class running "+ currentTime);
}
}
I am having an issue starting an alarm manager with a service. The service is initiated from the mainActicity with this code:
Intent intent = new Intent(this, YourService.class);
startService(intent);
I have defined the service in the manifest using this code:
<activity
android:name=".YourService"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="com.sjjgames.abortionappnoads.YOURSERVICE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".YourService" />
This is what the "YourService" class looks like:
package com.sjjgames.abortionappnoads;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
public class YourService extends Service
{
Alarm alarm = new Alarm();
public void onCreate()
{
super.onCreate();
}
public void onStartCommand(Context context,Intent intent, int startId)
{
alarm.SetAlarm(context);
}
#Override
public IBinder onBind(Intent intent)
{
return null;
}
}
The service is supposed to call a class called "Alarm" but the service never seems to start.
Your OnStartCommand has the wrong signature, so it is not overriding the base class, it should return an int. Using the #Override annotation helps catch these errors. Be sure to return one of the START_ codes that correspond to how you want your service run. See Service Lifecycle for more details.
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
I'm trying to create a reminder application that pops up a reminder in the status bar. As I understand, the Android NotificationManager is the standard tool to use to schedule notifications however a BootService is needed in order to re-schedule notifications as scheduled events do not survive across boots.
I've pieced together an application below which schedules a single reminder at boot time, and pops up a notification in the status bar. If you click the notification, it launches MainActivity which, in the future, will have options to add more reminders, delete them, or whatever.
The problem I'm having is that the reminder works correctly the first time however it seems to be re-scheduling itself and popping up again at random times for some reason. Should I be launching another activity rather than the one which installs the BootAlarmService?
UPDATE:
So I think I found some clues with logcat. Apparently the Service is crashing and being restarted which is resetting the Notification. Any ideas why this is?
UPDATE II : code changed to working model
ActivityManager I No longer want com.example.alarm_boot_test (pid 1428): hidden #16
ActivityManager W Scheduling restart of crashed service com.example.alarm_boot_test/.BootAlarmService in 5000ms
ActivityManager W Scheduling restart of crashed service com.example.alarm_boot_test/.NotificationAlarmService in 15000ms
ActivityManager I Start proc com.example.alarm_boot_test for service com.example.alarm_boot_test/.BootAlarmService: pid=2321 uid=10069 gids={}
dalvikvm D Debugger has detached; object registry had 1 entries
szipinf D Initializing inflate state
BootAlarmService D oncreate()
BootAlarmService D alarm set for Thu Jan 17 08:03:00 CST 2013
MainActivity.java
package com.example.alarm_boot_test;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity
{
#Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_main);
}
}
BootAlarmService.java
package com.example.alarm_boot_test;
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class BootAlarmService extends Service
{
private final String TAG = this.getClass ().getName ();
#Override
public void onCreate ()
{
Log.d (TAG, "oncreate()");
super.onCreate ();
}
#Override
public int onStartCommand (Intent intent, int flags, int startId)
{
Log.d (TAG, "alarm_test: BootAlarmService.onStartCommand() Received start id " + startId + ": " + intent);
// if intent == null, service has been killed/restarted by system
if (intent != null)
createNotificationOnBoot();
else
Toast.makeText (getBaseContext (), "Intent was null in BootAlarmService.", Toast.LENGTH_LONG).show();
return START_STICKY;
}
private void createNotificationOnBoot ()
{
Intent inotify = new Intent(this , NotificationAlarmService.class);
inotify.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
AlarmManager amgr = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, inotify, 0);
// go off two mins from now
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, calendar.get (Calendar.MINUTE) + 2);
amgr.set (AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis (), pendingIntent);
Log.d (TAG, "alarm set for " + calendar.getTime ().toString ());
}
#Override
public IBinder onBind (Intent intent)
{
return null;
}
}
BootReceiver.java
package com.example.alarm_boot_test;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver
{
#Override
public void onReceive (final Context context, final Intent bootintent)
{
Intent i = new Intent ();
i.setAction ("com.example.alarm_boot_test.BootAlarmService");
context.startService (i);
}
}
NotificationAlarmService.java
package com.example.alarm_boot_test;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
public class NotificationAlarmService extends Service
{
private final String TAG = this.getClass().getName ();
#Override
public void onCreate ()
{
super.onCreate ();
}
#Override
public int onStartCommand (Intent intent, int flags, int startId)
{
Log.d (TAG, "alarm_test: NotificationAlarmService.onStartCommand()");
if (intent != null)
createNotification ();
else
Toast.makeText (getBaseContext (), "Intent was null in NotificationAlarmService.", Toast.LENGTH_LONG).show();
return super.onStartCommand (intent, flags, startId);
}
private void createNotification()
{
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(android.R.drawable.stat_sys_warning, "Note from AlarmService", System.currentTimeMillis());
Intent i = new Intent(this, ViewReminder.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, 0);
notification.setLatestEventInfo(this, "New Notification", "You have been notified by AlarmService", pendingIntent);
notificationManager.notify(10001, notification);
}
#Override
public IBinder onBind (Intent intent)
{
return null;
}
}
*activity_main.xml*
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Service started! Reboot!" />
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.alarm_boot_test"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<service android:name="com.example.alarm_boot_test.BootAlarmService" >
<intent-filter>
<action android:name="com.example.alarm_boot_test.BootAlarmService" >
</action>
</intent-filter>
</service>
<receiver android:name="com.example.alarm_boot_test.BootReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" >
</action>
</intent-filter>
</receiver>
<service android:name="com.example.alarm_boot_test.NotificationAlarmService" >
</service>
<activity
android:name="com.example.alarm_boot_test.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
In case it helps someone else, I think I needed to check the passed Intent for NULL in the onStartCommand() method both in BootAlarmService.java as well as NotificationAlarmService.java. Only been testing it a couple days but it looks like the Intent is NULL if the system kills/restarts the service. Simply testing for this allowed me to create the notification only when the service is started at Boot-time (when the passed Intent is NOT null).
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Trying to start a service on boot on Android
BroadcastReceiver
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class StartActivityAtBoot extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent i = new Intent(context, CompareIMSI.class);
context.startService(i);
}
}
}
CompareSIM.java
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.telephony.TelephonyManager;
import android.widget.Toast;
public class CompareIMSI extends Service{
Context context;
TelephonyManager operator;
#Override
public IBinder onBind(Intent intent) {
return null;
}
#Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Service Created", Toast.LENGTH_LONG).show();
//compareSIM();
}
#Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
#Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
compareSIM();
}
public void compareSIM(){
final String STORAGE = "Storage";
SharedPreferences unique = getSharedPreferences(STORAGE, 0);
final String storedIMSI = unique.getString("simIMSI", "");
final String currentIMSI = getSubscriberId().toString();
if (!storedIMSI.equals(currentIMSI)){
Intent i = new Intent(CompareIMSI.this, ScreenLockActivity.class);
startActivity(i);
}
}
public String getSubscriberId(){
String IMSI = null;
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);
IMSI = m_telephonyManager.getSubscriberId();
return IMSI;
}
}
I would like the application to start the compareSIM service upon boot up, during boot up, this service will run as the current attached SIM card IMSI will be retrieved and matched with the already saved IMSI, once they are different the user will be brought to a login layout. I want to perform this during boot up but failed to do so... Kindly advice me on the coding, thanks
floow these steps for stating your service on BOOT:
Step 1: In AndroidManifest.xml add BOOT_COMPLETED permission as:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Step 2: In AndroidManifest.xml Register your Reciver as:
<receiver android:name=".StartActivityAtBoot" android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
Step 3: In AndroidManifest.xml Register your Service as:
<service android:name=".CompareIMSI"> </service>
Step 3: In StartActivityAtBoot Start your service as:
public class StartActivityAtBoot extends BroadcastReceiver
{
static final String ACTION = "android.intent.action.BOOT_COMPLETED";
public void onReceive(Context context, Intent intent)
{
if (intent.getAction().equals(ACTION))
{
context.startService(new Intent(context,
CompareIMSI.class), null);
Toast.makeText(context, "CompareIMSI service has started!", Toast.LENGTH_LONG).show();
}
}
}
This is all about Starting a Service on Boot.Thanks
You need to register the BroadcastReceiver in the Android manifest, like this:
<receiver android:name=".StartActivityAtBoot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
Also make sure that you have this permission in the manifest:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Check Your androidManifest file. You need to add receiver at androidManifest file.
<receiver android:name=".......StartActivityAtBoot" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>