我正在开发一个应用程序来设置警报以触发通知提醒我有关电视节目的内容
现在我将有关警报的数据存储在数据库中,但重新启动后所有警报都被删除
我曾经receiver
在接收BOOT_COMPLETED
时设置警报,但是当我在其中设置警报时,警报会触发另一个接收器来设置通知
我该怎么做
这是代码:
清单.xml
<receiver android:name=".NotAlarm" />
<receiver android:name=".BootCompletedReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
BootCompletedReceiver.java
这些行有错误:-
1 - 意图 alarmIntent = new Intent(this, NotAlarm.class);
2 - am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
package com.shadatv.shada;
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
public class BootCompletedReceiver extends BroadcastReceiver {
public DAOTimes timeDatabase = null;
AlarmManager am;
@Override
public void onReceive(Context context, Intent intent) {
Cursor allNotifs = timeDatabase.getAllNotifications();
if (allNotifs.moveToFirst()) {
do{
Intent alarmIntent = new Intent(this, NotAlarm.class);
String noPrName = allNotifs.getString(allNotifs.getColumnIndex("_noprogram")).toString().trim();
String noTime = allNotifs.getString(allNotifs.getColumnIndex("_notime")).toString().trim();
intent.setAction(noTime);
intent.putExtra("nameSelected", noPrName);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
new Intent(), PendingIntent.FLAG_CANCEL_CURRENT);
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, Long.valueOf(noTime),
7 * 24 * 60 * 60 * 1000, pendingIntent);
}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;
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);
// CharSequence ticker = (CharSequence) (R.string.noTitle);
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);
}
}
现在,我如何修改此代码以正确运行?