Файл ReminderBootUp.java содержит код для планирования вашей активности в конкретное время
package com.app.reminder;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
public class ReminderBootUp extends BroadcastReceiver {
private SQLiteDatabase myDataBase = null;
private Cursor rs = null;
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
try {
long alarmTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(
"2010-12-21 12:00").getTime();
int id = 1;
Date date = new Date();
if (date.getTime() <= alarmTime) {
Intent notifyIntent = new Intent(context, youractivity.class);
PendingIntent intent = PendingIntent.getBroadcast(context, id,
notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager am = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, alarmTime, intent);
}
} catch (Exception e) {
Log.e("Exception", e.getMessage(), e);
}
}
}
Вы должны добавить эту строку в файл Manifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED">
<receiver android:name="ReminderBootUp" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" android:enabled="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</receiver>
этот код будет работать после загрузки устройства ...
если вы хотите запустить приложение в обычном режиме,
напишите как наш нормальный код