Most of the time user needs to start a application on boot up, which needs to be auto start. I have searched a lot but didn;t find a good tutorial, but somehow I have managed it and it is working in my My Touch phone. Step to follow
1. Manifest FIle
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.events">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.VIBRATE" />
<application>
<receiver android:name=".MyBroadcastreceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service android:name=".MyService" />
</application>
</manifest>
2. Receiver
package com.android.events;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class MyBroadcastreceiver extends BroadcastReceiver {
public static final String TAG = "Rajesh";
@Override
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent pushIntent = new Intent(context, MyService.class);
context.startService(pushIntent);
}
}
}
3. MyService.class could be anything which extends Service
Hope this will help you :-)
No comments:
Post a Comment