我试图在每天早上 5 点设置一个触发器,以使手机为 USER_PRESENT 广播做好准备,但是一旦服务启动,触发器就会关闭。服务 (PAService) 通过使用stopService和startService打开主活动来关闭和打开。此代码在模拟器中运行良好,但不适用于实际的 Android 手机。
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;
}
}
临摹微笑
相关分类