且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

机器人:机器人能AlarmManager唤醒设备来执行计划任务?

更新时间:2023-11-18 23:48:28

是的u能我想类似,但不是exactly..i试图在每天上午9点至下载的内容调用设备我用这块code

Yes u can i tried something similar to that but not exactly..i tried invoking the device every day at 9.00AM to download the contents i used this piece of code

PowerManager pm = (PowerManager) context
            .getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, "");
    wl.acquire();

    wl.release();

这是我的实现:   用于设置Alaram

This was my implementation: Used to set the Alaram

 AlarmManager am = (AlarmManager) context
            .getSystemService(Context.ALARM_SERVICE);
     Calendar calendar = Calendar.getInstance();
     calendar.setTimeInMillis(System.currentTimeMillis());
     calendar.add(Calendar.MINUTE, 10);
     calendar.add(Calendar.SECOND, 00);
     //alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
     am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000*60*1, pi);

BroadcastReciever:

BroadcastReciever:

Register BroadcastReciever:
PowerManager pm = (PowerManager) context
            .getSystemService(Context.POWER_SERVICE);
    PowerManager.WakeLock wl = pm.newWakeLock(
            PowerManager.PARTIAL_WAKE_LOCK, "");
    wl.acquire();
    // Put here YOUR code.

    Intent startAutoSyncService = new Intent(context,
            AppoinmentService.class);
    context.startService(startAutoSyncService);

    wl.release();