我開發了一個新的應用程序什麼顯示電視節目的時間,我想提醒這個時間..這是行之有效的,但重新啓動後,所有報警都刪除,然後我用接收器BOOT_COMPLETED
行動,從database
retreive數據和復位重啓直接畢竟alarms
,但它不工作重新啓動後報警不會重置
這是我的代碼:
的manifest.xml
<receiver android:name=".NotAlarm" />
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
BootCompletedReceiver.java
package com.shadatv.shada;
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.widget.Toast;
public class BootCompletedReceiver extends BroadcastReceiver {
public DAOTimes timeDatabase;
Cursor allNotifs;
AlarmManager am;
@Override
public void onReceive(Context context, Intent intent) {
timeDatabase = new DAOTimes(context);
allNotifs = timeDatabase.getAllNotifications();
if (allNotifs.moveToFirst()) {
do{
String noPrName = allNotifs.getString(allNotifs.getColumnIndex("_noprname")).toString().trim();
String noTime = allNotifs.getString(allNotifs.getColumnIndex("_notime")).toString().trim();
Intent alarmIntent = new Intent(context, NotAlarm.class);
alarmIntent.setAction(noTime);
alarmIntent.putExtra("nameSelected", noPrName);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
alarmIntent, PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, Long.valueOf(noTime),
7 * 24 * 60 * 60 * 1000, pendingIntent);
Toast.makeText(context,
"name : " + Long.valueOf(noTime),
Toast.LENGTH_LONG).show();
}while(allNotifs.moveToNext());
}
}
}
NotAlarm.java
package com.shadatv.shada;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class NotAlarm extends BroadcastReceiver {
NotificationManager nm;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
NotificationManager nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
builder.setSmallIcon(android.R.drawable.btn_star);
builder.setTicker("تذكير");
Notification notify = builder.getNotification();
CharSequence title = intent.getExtras().getString("nameSelected");
CharSequence details = "تذكير - برنامج " + title;
PendingIntent pending = PendingIntent
.getActivity(context, 0, new Intent(), 0);
notify.setLatestEventInfo(context, title, details, pending);
nm.notify(0, notify);
Toast.makeText(context,
"noti : " + title,
Toast.LENGTH_LONG).show();
}
}
和某些微量元素,當你看到我把Toast
在BootCompletedReceiver.java
和NotAlarm.java
第一Toast
在重新啓動後顯示,但另一個不
分別
寫代碼是這個解決了嗎? – Signcodeindie 2013-04-10 09:58:23
是的,我發現解決方案 – 2013-04-13 04:26:09