search

Home  >  Q&A  >  body text

android - 安卓如何实现指纹解锁手机后自动启动一段代码(或某APP)?

背景:想实现驾车时有话想说给某微信好友老王,用指纹解锁后自动启动微信APP,以实现不用低头看手机 就能给老王发出一段语音。
流程如下:

1、指纹解锁手机。手机解锁
2、手指仍不离开指纹感应器,(手机检测指纹感应器被按下了2s)就自动启动微信
3、微信启动以后,调用AccessbilityServices或Root模拟点击等方式,点击老王头像
4、切换到语音输入模式,并模拟点击,自动按下微信“录音”按键
5、检测手指是否还在感应器上,如果手指离开了,就模拟点击松开微信“录音”,语音发送出去。

目前的问题在于:如何将指纹解锁与程序启动关联起来?比如用中指指纹解锁后,自动唤醒写好的Services?(然后这个有着Root权限的Services就可以完成2——4的流程了)
PHPzPHPz2772 days ago528

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-18 09:05:58

    You can dynamically register lock screen broadcast monitoring in Service to monitor the user's unlocking behavior. The service ensures that it stays in the background. Once the unlocking broadcast is received, corresponding business operations will be performed.

    1.Register screen broadcast

    IntentFilter filter = new IntentFilter();
    filter.addAction(Intent.ACTION_SCREEN_ON);
    filter.addAction(Intent.ACTION_SCREEN_OFF);
    //解锁
    filter.addAction(Intent.ACTION_USER_PRESENT);
    registerReceiver(new ScreenReceiver(), filter);
    

    2. Perform related operations in the unlock broadcast

    private class ScreenReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            switch (intent.getAction()){
                case Intent.ACTION_SCREEN_ON:
                    // 开屏
                    Log.i(TAG, "onReceive: ON");
                    break;
                case Intent.ACTION_SCREEN_OFF:
                    // 锁屏
                    Log.i(TAG, "onReceive: OFF");
                    break;
                case Intent.ACTION_USER_PRESENT:
                    // 解锁屏幕
                    Log.i(TAG, "onReceive: PRESENT");
                    //do something 
                    break;
                default:
                    break;
            };
        }
    }

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:05:58

    A question about the situation, it’s all about fingerprint unlocking. How do you distinguish between driving and non-driving states? Back to the topic, the previous answerer's screen broadcast monitoring is a possible idea. Maybe your second step can be achieved, but even if you have the assistance of AccessbilityServices or root, I'm afraid you can't find Lao Wang. Not talking about technology, this is a bad thing.

    reply
    0
  • Cancelreply