我的代碼自動啓動爲啓動設備的Android後不自動啓動:爲什麼服務執行
public class AutoStart extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
SetAlarm(context);
}
}
public void SetAlarm(Context context) {
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, ServiceUpdateData.class);
// PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
PendingIntent pi = PendingIntent.getService(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, 30);//
int dbtime = 10;
int time = 1000 * 60 * dbtime;
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
time, pi); // Millisec * Second * Minute
Toast.makeText(context, "Service Started Again", Toast.LENGTH_LONG)
.show();
}
}
我在androidmainifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
爲什麼我的後服務不自動啓動加啓動設備android。 你能幫我嗎?
,其Android版本,你的測試? – user936414