1

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 class MyStartUpReciever extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Intent ii = new Intent(); ii.setAction("com.sat.servicetrack"); context.startService(ii); } } 

and this is my manifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ServiceTrack" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MyStartupReciever"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.HOME" /> </intent-filter> </receiver> <service android:enabled="true" android:name=".MyService" > <intent-filter> <action android:name="com.sat.servicetrack" /> </intent-filter> </service> </application> 

Am I missing anything?

6
  • what about running the same code on simulator ? Commented May 16, 2012 at 7:10
  • how can i know it's work in emulator or not?? @moujib Commented May 16, 2012 at 8:03
  • add a log on your onReceive method ... Commented May 16, 2012 at 8:05
  • Close the emulator and start again. Commented May 16, 2012 at 10:40
  • can you please show whole code of AndroidManifest.xml ? Commented May 17, 2012 at 8:43

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

5 Comments

i have try put your code, i restart my device..but my service still not running..how it's??sorry for bother you :)
i have got error like this 05-16 15:24:21.766: ERROR/AndroidRuntime(292): Caused by: java.lang.ClassNotFoundException: com.sat.servicetrack.MyStartupReciever in loader dalvik.system.PathClassLoader[/data/app/com.sat.servicetrack-1.apk] what it is?? @Veljko
try to start some dummy activity, which starts your service. instead of running service immediatly.
i have got error like this 05-16 15:24:21.766: ERROR/AndroidRuntime(292): Caused by: java.lang.ClassNotFoundException: com.sat.servicetrack.MyStartupReciever in loader dalvik.system.PathClassLoader[/data/app/com.sat.servicetrack-1.apk] what it is?? @Veljko
have you just copied my code? mine receiver is called BootUpReceiver and yours MyStartUpReciever. Check that...you have made some typo for sure.
2

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> 

Comments

0
 @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

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.