Android屏幕唤醒

时间:2020-03-18 08:06:46

标签: android

我的项目通过蓝牙连接到硬件。现在我需要在屏幕锁定状态下接收到信号后拨打电话,但是我可以接收到蓝牙信号但是在屏幕锁定状态下无法拨打电话。这是我的代码

     case ID.MSG_USER_ALARM:
                Toast.makeText(mContext, "Help", Toast.LENGTH_LONG).show();
                Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                long[] pattern = {100, 400, 100, 400};
                vibrator.vibrate(pattern, -1);
                Utils.wakeUpAndUnlock(InticareMRApplication.getContext());

                if (TextUtils.isEmpty(CacheManager.getString(Constant.KEY_CONTACT_PHONE, ""))) {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"));
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + CacheManager.getString(Constant.KEY_CONTACT_PHONE, "")));
                    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                        return;
                    }
                    startActivity(intent);
                }
                break;

public static void wakeUpAndUnlock(Context context) {
        KeyguardManager km;
        KeyguardManager.KeyguardLock kl;
        PowerManager pm;
        PowerManager.WakeLock wl;

        pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);

        wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "power:bright");

        wl.acquire();

        km = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
        kl = km.newKeyguardLock("unLock");

        kl.disableKeyguard();
    }

0 个答案:

没有答案