当锁屏状态下,用户在锁屏状态下选择了对通知操作的肯定响应,如何添加代码提示解锁?这是我添加到通知构建器的当前积极通知操作的代码,当选择此操作时,我在类中添加了一个 Intent ,它扩展了 IntentService 以导航到应用程序中的一个 Activity :
private static Action yesLetsGo(Context context) {
Intent intent = new Intent(context, NotificationIntentService.class);
intent.setAction(NotificationTasks.ACTION_YES_LETS_GO_NOTIFICATION);
PendingIntent yesLetsGo = PendingIntent.getService(
context,
ACTION_YES_LETS_GO_PENDING_INTENT_ID,
intent,
PendingIntent.FLAG_UPDATE_CURRENT);
Action yesLetsGoAction = new Action
(R.drawable.ic_launcher_background,
"Yes Lets Go",
yesLetsGo);
Log.i("Notification Utils","yesLetsGo method called");
return yesLetsGoAction;
}
最佳答案
要在 Android 中启用或禁用锁屏,我们需要获取 KeyguardManager
的实例
KeyguardManager keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
KeyguardLock lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
以及禁用锁的使用,
lock.disableKeyguard();
当然我们需要Manifest中的权限
android.permission.DISABLE_KEYGUARD
关于java - 当从 Android 的锁定屏幕上单击通知操作时,如何以编程方式解锁屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47947025/