AddProximityAlert和设备唤醒-Android
我有个问题。AddProximityAlert不想唤醒我的设备。我没有任何接收器(在这种情况下我没有,因为无法注销它)。我只是通过以下方式推动intent添加ProximityIntent:AddProximityAlert和设备唤醒-Android,android,Android,我有个问题。AddProximityAlert不想唤醒我的设备。我没有任何接收器(在这种情况下我没有,因为无法注销它)。我只是通过以下方式推动intent添加ProximityIntent: Intent myIntent = new Intent(cxt, alarmView.class); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent proximityIntent = PendingIntent.getA
Intent myIntent = new Intent(cxt, alarmView.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent proximityIntent = PendingIntent.getActivity(cxt, records.get(pos).process,myIntent, 0);
locationManager.addProximityAlert(records.get(pos).x,
records.get(pos).y, records.get(pos).r, // metry
-1, proximityIntent);
我尝试将PowerManager.newWakeLock插入myIntent.onCreate,但它不起作用(我想是因为在唤醒之前没有创建活动?)
有可能为我唤醒手机或以其他方式唤醒手机的意图提供任何参数?
(如果可能,我还需要解锁设备)您在alarmView
活动中的onCreate()方法应该如下所示:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/**** Turn the screen on and show your activity ****/
android.view.Window window = getWindow();
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
window.addFlags(android.view.WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
window.setContentView(R.layout.activity_alarm_view);
/***************************************************/
/**** Rest of your code as it is ****/
/* ---------------------------- ****/
/************************************/
}
在这里,我假设此活动的布局文件名为
activity\u alarm\u view.xml
它可以工作,谢谢:)但我仍然想知道为什么addProximityAlert不会自动唤醒我的设备,在我阅读的文档中,我读到“如果屏幕进入睡眠状态,检查接近警报仅每4分钟发生一次”,那么它是否应该唤醒它,因为它检查它的状态?@kolek:文档说明,当设备处于睡眠状态时,仍然会进行接近警报检查,但每4分钟检查一次。要进行这些检查,不要求设备完全唤醒;只有cpu需要唤醒,才能执行检查。这节省了电池,同时确保设备可以进行接近检查、位置检查、处理广播消息等。