我正在尝试在指定的时间设置闹钟,但它没有被我的reciver捕获。
设定:
Intent intent = new Intent(this, ActionReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
Calendar current = Calendar.getInstance();
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, (current.getTimeInMillis() + 60000),3600000, pendingIntent);
这是我的收发器:
public class ActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras(); //breakpoint here that doesn't get triggered
}
}
我已将这些值放在我的清单中:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<receiver android:name="com.project.ActionReceiver" android:enabled="true" />
不确定有什么问题...谢谢!
答案 0 :(得分:4)
终于让接收器开火了!我在清单中添加了以下代码:
<receiver
android:name="com.project.ActionReceiver"
android:exported="true" >
<intent-filter>
<action android:name="com.project.ActionSetter" >
</action>
</intent-filter>
</receiver>
答案 1 :(得分:1)
清单中接收者的姓名应为班级名称,例如:
<receiver android:name="com.project.ActionReceiver">
顺便说一句,设置一个动作是一种更好的做法。
Intent intent = new Intent(this, ActionReceiver.class);
intent.setAction("com.project.action.ALERM");
在清单中
<receiver android:name="com.project.ActionReceiver">
<intent-filter>
<action android:name="com.project.action.ALERM"/>
</intent-filter>
</receiver>
答案 2 :(得分:1)
尝试将android:name
的{{1}}属性更改为receiver
的完全限定类名。类似的东西:
ActionReceiver