警报接收器服务无法正常工作

时间:2016-02-14 10:01:42

标签: java android service alarmmanager alarm

这是我的主要活动,其中称为警报接收器服务

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);

这是我的MyBroadcastReceiver类

public class MyBroadcastReceiver  extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {

    String LOG_TAG="DevicePolicyAdmin";
    Log.v(LOG_TAG, "Service Started");
    Calendar c = Calendar.getInstance();
    int hour=c.get(Calendar.HOUR_OF_DAY);
    int  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);
    MainActivity.minochaDevicePolicyManager.resetPassword(str, 0);
}
}

这是什么问题?在logcat中的LOG"启用策略"没有来。这意味着服务还没有被调用。这段代码怎么了?

0 个答案:

没有答案