0
我讀了很多教程,但沒有得到解決方案。我想使用AlarmManager進行同步。我希望當我選擇「15分鐘後」複選框時,在系統中設置當前時間的警報(如何在數據庫中保存該特定時間,重要的是在數據庫中節省時間?)和刷新列表每15分鐘。我不知道如何綁定checkBoxes值和警報,以及如何使它成爲可能。完全卡住。如何使用PendingIntent.activity()或PendingIntent.getBroadcast使用AlarmManager?
我的代碼:
private final class syncOkClickListener implements DialogInterface.OnClickListener
{
public void onClick(DialogInterface dialog, int which)
{ //Implement search method here
if(after15mint.isChecked())
{
// Some code!!! or Alarm Manager !!!
// Toast.makeText(getApplicationContext(), "15 Minute checked", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Default", Toast.LENGTH_LONG).show();
}
}
BroadcastReceiver的活動:
public class BroadCastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
}
public void SetAlarm(Context context)
{
AlarmManager alarmManager = (AlarmManager)context.getSystemService(context.ALARM_SERVICE);
Intent syncIntent = new Intent(context, BroadCastReceiver.class);
syncIntent.putExtra("sync", 0);
PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, syncIntent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000*20, pIntent);
}
public void CancelAlarm(Context context)
{
Intent intent = new Intent(context, BroadCastReceiver.class);
PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.cancel(sender);
}
}
任何建議將是有益的。謝謝。
嗨感謝您的回覆,廣播接收器代碼是否正常? – Shweta 2013-04-24 05:07:49