файл декларации
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="onchip.automobile.caraccessory1"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<receiver
android:name=".Onchip_BroadcastReceiver">
<intent-filter >
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service
android:name=".Onchip_BackgroundService">
<intent-filter >
<action android:name="onchip.automobile.caraccessory1.BACKGROUND_SERVICE" />
</intent-filter>
</service>
</application>
</manifest>
Onchip_BroadcastReceiver.java
package onchip.automobile.caraccessory1;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class Onchip_BroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent serviceIntent = new Intent("onchip.automobile.caraccessory1.BACKGROUND_SERVICE");
context.startService(serviceIntent);
}
}
Onchip_BackgroundService.java
package onchip.automobile.caraccessory1;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;
public class Onchip_BackgroundService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
Toast.makeText(this, "Onchip_BackgroundService Created", Toast.LENGTH_LONG).show();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(this, "Onchip_BackgroundService Started", Toast.LENGTH_LONG).show();
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Onchip_BackgroundService Destroyed", Toast.LENGTH_LONG).show();
}
}