I want to start my application when phone startup
I just follow tutorial from here but it doesn\'t work in my device. Please see my method:
public c
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
context.startService(new Intent(context, BootService.class));
}
}
and next you should implements BootService class extended Service
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);
}
}
Your code seems to be correct, but try using PendingIntent ;) Hope it helps you
try like this....
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, BootingActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
in manifest file...
<receiver android:name=".BroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</receiver>
You are not calling the Service.
Code like this.
Intent objIntent= new Intent(context, MyService.class);
context.startService(objIntent);
Click Here to know how to start service from broadcast receiver