第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

服務(wù)啟動(dòng)后觸發(fā)警報(bào)而不是設(shè)置時(shí)間

服務(wù)啟動(dòng)后觸發(fā)警報(bào)而不是設(shè)置時(shí)間

Qyouu 2021-10-20 15:01:09
我試圖在每天早上 5 點(diǎn)設(shè)置一個(gè)觸發(fā)器,以使手機(jī)為 USER_PRESENT 廣播做好準(zhǔn)備,但是一旦服務(wù)啟動(dòng),觸發(fā)器就會(huì)關(guān)閉。服務(wù) (PAService) 通過使用stopService和startService打開主活動(dòng)來關(guān)閉和打開。此代碼在模擬器中運(yùn)行良好,但不適用于實(shí)際的 Android 手機(jī)。public class PAService extends Service {static boolean is_ready_to_speak = false;PendingIntent pendingIntent;public PAService() {}public class ScreenReceiver extends BroadcastReceiver {    @Override    public void onReceive(Context context, Intent intent) {        if(is_ready_to_speak)        {            PASpeak paspeak = new PASpeak();            paspeak.sayit(getApplicationContext(),"You're using your phone for the first time this morning");           is_ready_to_speak = false;        }    }}public static class AlarmReceiver extends BroadcastReceiver {    public AlarmReceiver()    {        Log.d("AlarmReceiver func called","alarm receiver func called");    }    @Override    public void onReceive(Context context, Intent intent) {        Log.d("RECEIVED BROADCAST", "Sometype of ALARM Broadcast received");        PASpeak paspeak = new PASpeak();        paspeak.sayit(context.getApplicationContext(),"ALARM ALARM ALARM");        is_ready_to_speak = true;    }}
查看完整描述

1 回答

?
臨摹微笑

TA貢獻(xiàn)1982條經(jīng)驗(yàn) 獲得超2個(gè)贊

manager.setRepeating(AlarmManager.RTC_WAKEUP,

            calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, // for repeating

            // in every 24

            // hours

            pendingIntent);

的2nd parameter,觸發(fā)時(shí)間觸發(fā)報(bào)警器立即如果calendar.getTimeInMillis()是在過去。所以發(fā)生的事情是你可能在晚上 7 點(diǎn)打開應(yīng)用程序。您希望鬧鐘在第二天早上 5 點(diǎn)響起,但您calendar.getTimeInMillis()會(huì)在同一天早上 5 點(diǎn)響起 。所以你需要為此添加一個(gè)檢查:


Calendar calendar = Calendar.getInstance();

// calendar.setTimeInMillis(System.currentTimeMillis()); // YOU DON'T NEED THIS LINE

calendar.set(Calendar.HOUR_OF_DAY, 5);

calendar.set(Calendar.MINUTE, 0);

calendar.set(Calendar.SECOND, 0);


Calendar current = Calendar.getInstance();


int curTime = current.getTimeInMillis();

int alarmTime = calendar.getTimeInMillis();


if (alarmTime >= curTime){

   manager.setRepeating(AlarmManager.RTC_WAKEUP,

        alarmTime, AlarmManager.INTERVAL_DAY, // for repeating

        // in every 24

        // hours

        pendingIntent);

}else{

   calendar.add(Calendar.DAY_OF_MONTH, 1);

   int alarmTime = calendar.getTimeInMillis();

   manager.setRepeating(AlarmManager.RTC_WAKEUP,

        alarmTime, AlarmManager.INTERVAL_DAY, // for repeating

        // in every 24

        // hours

        pendingIntent);

}


查看完整回答
反對(duì) 回復(fù) 2021-10-20
  • 1 回答
  • 0 關(guān)注
  • 169 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)