java - 当从 Android 的锁定屏幕上单击通知操作时,如何以编程方式解锁屏幕?

标签 java android

当锁屏状态下,用户在锁屏状态下选择了对通知操作的肯定响应,如何添加代码提示解锁?这是我添加到通知构建器的当前积极通知操作的代码,当选择此操作时,我在类中添加了一个 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/

相关文章:

java - 使用 Java 中的 Apache Maths 进行时间序列的简单回归

Java Spring JSON解析错误: Cannot deserialize instance out of START_ARRAY token

java - Java中的正则表达式非法字符

java - 更改 JTabbedPane 的选项卡时,关闭在另一个 JInternalFrame 中打开的已打开的 JInternalFrame

android - Android 中的内存缓存

android - FirebaseRemoteConfig : Cannot resolve symbol

java - 如何在 AsyncTask 中运行 ProgressDialog

android - 无法创建 MediaPlayer,音板错误

android - 从 Android 上的相机录制视频到 mp4

android - 如何在单选按钮上设置图像