这是我的代码
当我设置闹钟并在闹钟无效后重启手机
示例 我下午4点设置闹钟
有些我如何在下午3点重启手机
警报在下午3点响起
不是下午4点
Boot_receiver
public class Boot_Receiver extends BroadcastReceiver {
@SuppressWarnings("static-access")
@Override
public void onReceive(Context context, Intent intent) {
SettingswithSliding aw=new SettingswithSliding();
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
// aw.setAlarm(8, null);
Intent i = new Intent(context, Notification_Quote.class);
try {
MyBaseClass.editor_base = MyBaseClass.preferences_base.edit();
MyBaseClass.editor_base.putInt("Restarted", 1);
MyBaseClass.editor_base.commit();
Calendar calendar = Calendar.getInstance();
/*calendar.set(Calendar.HOUR_OF_DAY, 00);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);*/
Log.d("sdfn", "djfgv"+calendar);
AlarmManager alarmManager = (AlarmManager) context
.getSystemService(context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(
context, 0, i, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP,
calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
pendingIntent); // set repeating every 24 hours
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e("error", e.getMessage());
}
}
}else
{
Log.d("ram", "e");
}
}}
Notification_quote
public class Notification_Quote extends BroadcastReceiver {
NotificationManager nm;
String Quotename;
Long li;
Intent intent;
int Quote_id, flag;
Long l_time;
Cursor getQuote = null;
DatabaseHelper helper;
static int pi_id = 0;
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(context
.getApplicationContext());
l_time = pref.getLong("calendar_value", 0);
try {
helper = new DatabaseHelper(context);
helper.createDatabase();
helper.openDataBase();
getQuote = helper.getRandomQuote(1, "");
if (getQuote != null) {
getQuote.moveToFirst();
do {
Quote_id = getQuote.getInt(0);
Quotename = getQuote.getString(1).toString();
} while (getQuote.moveToNext());
}
getQuote.close();
} catch (NullPointerException ne) {
if (ne.getMessage() != null) {
Log.e("ERROR", ne.getMessage());
}
} catch (SQLException se) {
if (se.getMessage() != null) {
Log.e("ERROR", se.getMessage());
}
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e("ERROR", e.getMessage());
}
} finally {
try {
helper.close();
} catch (NullPointerException ne) {
if (ne.getMessage() != null) {
Log.e("null pointer ERROR", ne.getMessage());
}
} catch (Exception e) {
if (e.getMessage() != null) {
Log.e("ERROR", e.getMessage());
}
}
}
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = context.getString(R.string.app_name);
CharSequence message = Quotename;
Intent i = new Intent(context, Single_Quote.class);
Bundle bnd = new Bundle();
bnd.putInt(context.getString(R.string.package_name) + ".quote_day", 3);
Log.d("fe", "" + context.getString(R.string.package_name)
+ ".quote_day");
i.putExtras(bnd);
PendingIntent contentIntent = PendingIntent.getActivity(context,
++pi_id, i, PendingIntent.FLAG_UPDATE_CURRENT);
SharedPreferences preferences = PreferenceManager
.getDefaultSharedPreferences(context.getApplicationContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("Qid", Quote_id); // value to store
editor.commit();
/* SettingswithSliding sw=new SettingswithSliding();
sw.setAlarm(8,contentIntent );*/
Calendar calendar = Calendar.getInstance();
long time1 = System.currentTimeMillis();
// long time = calendar.getTimeInMillis();
Log.d("tome", ""+calendar+time1);
Notification notif = new Notification(R.drawable.ic_launcher, message,
time1);
Intent notificationIntent = new Intent(context, SettingswithSliding.class);
PendingIntent pie = PendingIntent.getActivity(context, 0, notificationIntent , 0);
Log.d("d", ""+notif);
notif.setLatestEventInfo(context, from, message, pie);
notif.ledARGB = 0xff00ff00;
notif.ledOnMS = 2000;
notif.ledOffMS = 1000;
notif.flags |= Notification.FLAG_SHOW_LIGHTS;
notif.flags |= Notification.FLAG_ONLY_ALERT_ONCE
| Notification.FLAG_AUTO_CANCEL;
long[] vibrate = { 0, 100, 200, 300 };
notif.vibrate = vibrate;
Uri sound = Uri.parse("android.resource://"
+ context.getApplicationContext().getPackageName() + "/"
+ R.raw.notification);
notif.sound = sound;
nm.notify(1, notif);
}}
这是我的代码
当我的手机重启时,警报在特定时间内无法正常工作
这里是我的最好的
<receiver android:name=".Boot_Receiver"
android:enabled="false" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>