所以即时尝试在我的Android应用中设置预定闹钟。所以设置报警服务如下。请告诉我它是否正确,因为它不起作用。
Context context=getApplicationContext();
alarmMgr = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(context, MyBroadcastReceiver.class);
alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
1000 * 60, alarmIntent);
以上是主要方法。现在我创建了一个接收器类
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Calendar c = Calendar.getInstance();
hour=c.get(Calendar.HOUR_OF_DAY);
minute=c.get(Calendar.MINUTE);
Calendar calendar = new GregorianCalendar(1990, 1, 1, hour, minute);
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm");
String date = sdf.format(calendar.getTime());
String str=date.charAt(0)+""+date.charAt(1)+""+date.charAt(3)+""+date.charAt(4);
minochaDevicePolicyManager.resetPassword(str,0);
}
}
这不起作用。为什么 我希望onReceive每分钟运行一次。代码好吗?
答案 0 :(得分:1)
您必须在receiver
中添加AndroidManifext.xml
才能收到警报。
<manifest ...>
<application ...>
...
<receiver android:name=".MyBroadcastReceiver" />
</application>
</manifest>