在Manifest.xml中,我编写了一个接收器来检测设备运动是否发生了变化
<receiver android:name="com.hanuman.sensor.receiver.SensorReceiver" >
<intent-filter
android:enabled="true"
android:exported="false" >
<action android:name="android.intent.action.USER_PRESENT" />
</intent-filter>
</receiver>
在接收器中,onReceive()方法代码是:
String action = intent.getAction();
if (action.equals(Intent.ACTION_USER_PRESENT)) {
System.out.println("User is present");
Intent s = new Intent(context, MainActivity.class);
s.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(s);
} else {
System.out.println("User is not present");
}
最后,我的问题是,当我的设备处于解锁状态时,它没有检测到传感器,然后它正在调用我的MainActivity,但我想要检测设备移动发生变化时,我想要在接收器中检测到。我该怎么做呢?
https://stackoverflow.com/questions/29604430
复制相似问题