我需要我的项目帮助,我应该让BroadcastReceiver在当前的锁定屏幕上启动全屏活动。 我在活动中尝试了这个:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("onCreate","success");
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP), "TAG");
wakeLock.acquire(10*60*1000L /*10 minutes*/);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
this.setShowWhenLocked(true);
this.setTurnScreenOn(true);
setContentView(R.layout.activity_stop);
}
BroadcastReceiver:
Intent i = new Intent(context,StopTheAlarm.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
AndroidManifest.xml:
<activity android:name=".Stop"
android:showOnLockScreen="true"
android:screenOrientation="sensorPortrait">
</activity>
但是在我的android 7.0.1手机上不起作用
答案 0 :(得分:0)
更新: 我删除了
this.setShowWhenLocked(true);
this.setTurnScreenOn(true);
导致应用崩溃的
答案 1 :(得分:0)
您的解决方案不适用于Android API 27及更高版本。使用此thread中的代码。