خرید بک لینک

Vote count: 0

On an Android 6.0 project, I am trying to unlock the phone using the proximity sensor.

This what I have for OnSensorChanged event:

    public void onSensorChanged(SensorEvent event) {
            proxValue = (event.values[0]); //sensor value stored in proxValue
            keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
            lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
            screenLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
    /*when service is ruing and phone is locked
     and proximity sensor value is less than 2.0 centimeters*/
            if(isMyServiceRuing(StartStopService.class) && lockStatus == true && proxValue < 2){
                Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
                v.vibrate(500); // vibrate for 500 ms 
                screenLock.acquire(); //to wake the phone up
                lock.disableKeyguard(); //to unlock the phone
                keyguardDisabled = true; // boolean to check keyguard status

            }
        }

On my ScreenReceiver I have:

public class ScreenReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            keyguardManager = (KeyguardManager)getSystemService(Activity.KEYGUARD_SERVICE);
            lock = keyguardManager.newKeyguardLock(KEYGUARD_SERVICE);
            screenLock = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(
                    PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
            if((intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) || !(intent.getAction().equals(Intent.ACTION_USER_PRESENT)))
            {
                lockStatus = true;
                if(keyguardDisabled){
                    lock.reenableKeyguard();
                    screenLock.release();
                    keyguardDisabled = false;

                }
            }
            else
            {
                lockStatus = false;
            }
        }
    }

The problem occurs when I call lock.disableKeyguard(). It unlocks and wakes up the phone successfully but phone freezes when I press the home button. What could be the solution or is there any other way to unlock the phone programmatically?

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 4 ارديبهشت 1395 ساعت: 6:56

صفحه بندی