繁体   English   中英

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

[英]How can I unlock screen programmatically when the notification action is clicked from lock screen in Android?

当屏幕被锁定并且用户从锁定屏幕选择对通知操作的积极响应时,如何添加代码以提示屏幕解锁? Here is the code to my current positive notification action that i have added to the notification builder, when this action is chosen I have added an intent in the class that extends the IntentService to navigate to an activity in the app:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM