接收器未在Alarm Manager android中调用

时间:2016-04-10 18:48:22

标签: android android-service alarmmanager android-permissions

嗨我需要在android中使用特定日期的通知。所以我用闹钟管理器来触发接收器。但是广播接收器没有呼叫。这是我的代码。

这是一段代码..

详细信息活动:

Log.e("alarm set", "cal" + cal.getTime());
        setAlarm(cal);

  private void setAlarm(Calendar targetCal){
    //this log got printed.
    Log.e("alarm set",""+targetCal.getTime());

    Intent intent = new Intent(Details.this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(Details.this, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, targetCal.getTimeInMillis(), pendingIntent);
}

But AlarmReceiver is not calling.

public class AlarmReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent arg1) {
    //this is not working.
    Log.e("alarm",";alarm");
    Toast.makeText(context, "Alarm received!", Toast.LENGTH_LONG).show();
    Intent service1 = new Intent(context, AlarmService.class);
    context.startService(service1);

}

}

我获得了许可,

  <uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

    <receiver
        android:name=".AlarmReceiver"
        android:process=":remote" />

    <service
        android:name=".AlarmService"
        android:enabled="true"
        android:exported="true"></service>

我无法找到我正在做的错误。

提前致谢。

0 个答案:

没有答案