76

My screen is dead and I want to unlock my phone so I can access it through Kies to back up my pictures.

I locked the phone through Android Device Manager, setting an easy password (I was hoping for an Unlock option once I locked it) and tried various methods to unlock it. For example:

adb shell input text 1234

Since I don't know what the lock screen looks like, I'm not sure of the correct inputs to unlock it.

I know the phone is on and that it responds to adb. I am also able to run apps on it through Eclipse.

It's a Samsung Galaxy S5 with Android 5.0.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
schoel
  • 793
  • 1
  • 6
  • 14
  • This is not a programming question; try asking here instead: http://android.stackexchange.com/ – GoBusto Mar 16 '15 at 08:37
  • Thanks I'll try there as well. However, if I can unlock my phone by uploading an app through Eclipse that would work as well. – schoel Mar 16 '15 at 08:55

14 Answers14

73

If you have to click OK after entering your passcode, this command will unlock your phone:

adb shell input text XXXX && adb shell input keyevent 66

Where

  • XXXX is your passcode.
  • 66 is the keycode of the OK button.
  • adb shell input text XXXX will enter your passcode.
  • adb shell input keyevent 66 will simulate clicking the OK button.
Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
Tien
  • 2,105
  • 17
  • 14
  • Thanks! After posting I tried this and got "Invalid pin code" (managed to see the screen through USB with Droid@Screen) even though I'm sure it was the correct pin. – schoel Mar 16 '15 at 18:44
  • 1
    @Tien Could you update your answer to use `XXXX` instead of `0000` and mention that `XXXX` is your passcode, as people will use `0000` without thinking. – Samveen Mar 20 '16 at 10:52
  • 11
    What if we have pattern password? – trusktr May 05 '16 at 18:58
  • 3
    What if you want **(1) turn on screen** (can use [this way](http://stackoverflow.com/a/41198273/5318303) for this part), **(2) swipe it up** (for showing pin/password input pad on android >= 5) **(3)** and then **input pin/password**? – Mir-Ismaili Dec 17 '16 at 12:32
  • 6
    I didn't tried to combine all above actions but I found this on stackoverflow to swipe up: http://stackoverflow.com/questions/25500567/is-it-possible-to-produce-continuous-swipe-action-on-the-touchscreen-with-adb I tried this "adb shell input touchscreen swipe 530 1420 530 1120" and it works – Tien Dec 23 '16 at 16:23
  • I tried this and it returned java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission. Anyone can help on this? – Vindex Oct 29 '21 at 08:11
  • before that you should issue adb shell input keyevent 26 if the screen is turned off. – Zibri Sep 19 '22 at 08:48
52

This command helps you to unlock phone using ADB

adb shell input keyevent 82 # unlock
Bhaskar
  • 911
  • 6
  • 18
52

Tested in Nexus 5:

adb shell input keyevent 26 #Pressing the lock button
adb shell input touchscreen swipe 930 880 930 380 #Swipe UP
adb shell input text XXXX #Entering your passcode
adb shell input keyevent 66 #Pressing Enter

Worked for me.

Yogeesh Seralathan
  • 1,396
  • 4
  • 15
  • 22
  • Instead of 26 and 66 you can also write POWER and ENTER, which are equivalent. You're also able to use this same trick to bypass the Google login verification screen by sending TAB and ENTER when the popup appears. Source: Pixel 7 testing and https://gist.github.com/arjunv/2bbcca9a1a1c127749f8dcb6d36fb0bc – Ray Foss Apr 15 '23 at 22:14
29

If you have USB-Debugging/ADB enabled on your phone and your PC is authorized for debugging on your phone then you can try one of the following tools:

scrcpy

scrcpy connects over adb to your device and executes a temporary app to stream the contents of your screen to your PC and you're able to remote control your device. It works on GNU/Linux, Windows and macOS.

Vysor

Vysor is a chrome web app that connects to your device via adb and installs a companion app to stream your screen content to the PC. You can then remote control your device with your mouse.

MonkeyRemote

MonkeyRemote is a remote control tool written by myself before I found Vysor. It also connects through adb and lets you control your device by mouse but in contrast to Vysor, the streamed screen content updates very slow (~1 frame per second). The upside is that there is no need for a companion app to be installed.

ns130291
  • 716
  • 7
  • 9
  • My Oneplus One screen broke and this to my rescue! I would like to try to unlock as well via dab commands. Will do it soon, thanks anyways – stack_ved Mar 28 '16 at 07:01
  • WOW! Vysor simply worked like charm on my rooted SGS4. Thanks a lot. Just a question out of curiosity- Does both Vysor and MonkeyRemote work for non-rooted phone? – bozzmob Apr 24 '16 at 09:31
  • Yes they work on non-rooted devices. The only requirements are USB-Debugging/ADB enabled and an authorized PC. – ns130291 Apr 30 '16 at 08:14
  • 1
    MonkeyRemote worked beautifully to unlock a broken screen of my Nexus 5. Thank you! – Alex P Dec 14 '16 at 03:57
  • MonkeyRemote did the trick perfectly. Thanks for sharing it. I'll send you a PR with some love :) – voghDev Jan 14 '19 at 10:29
  • Vysor is working great on Pixel XL, but quality is HORRIBLE without pro. – Ryan Leach Oct 25 '19 at 08:01
  • Awesome, Vysor is saving me here! –  Feb 03 '20 at 12:02
20

Another way just for your information.

Use an USB OTG cable and connect with an USB mouse, you can touch the screen by clicking your mouse !

Rocky Chen
  • 448
  • 3
  • 9
19

Below commands works both when screen is on and off

To lock the screen:

adb shell input keyevent 82 && adb shell input keyevent 26 && adb shell input keyevent 26

To lock the screen and turn it off

adb shell input keyevent 82 && adb shell input keyevent 26

To unlock the screen without pass

adb shell input keyevent 82 && adb shell input keyevent 66

To unlock the screen that has pass 1234

adb shell input keyevent 82 && adb shell input text 1234 && adb shell input keyevent 66
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • 1
    Some phones may need two "input keyevent 82" to unlock and get to the password entry in my experience. – Ivan Neeson Aug 07 '17 at 07:11
  • 1
    FYI there are a few alternative to keycode `82` to bring up the keyguard. I found that `23 (D-Pad center)`, `62 (space)` and `66 (enter)` also did the job. – Sam Jun 28 '20 at 02:05
14

if the device is locked with black screen run the following:

  1. adb shell input keyevent 26 - this will turn screen on
  2. adb shell input keyevent 82 - this will unlock and ask for pin
  3. adb shell input text xxxx && adb shell input keyevent 66 - this will input your pin and press enter, unlocking device to home screen
Isaac Morris
  • 336
  • 2
  • 11
4

If you had MyPhoneExplorer installed and connected (not sure this is a must, happened to be my setup already), you could use it to control the screen with your computer mouse. It connects via ADB, for which your normal USB cable is enough.

Another solution I found that even worked without a reboot is updating tables in settings.db and locksettings.db I had to switch to root to open the settings.db though:

 adb shell
 su
 sqlite3 /data/data/com.android.providers.settings/databases/settings.db
 update secure set value=1 where name='lockscreen.disabled';
 .quit
 sqlite3 /data/system/locksettings.db
 update locksettings set value=0 where name='lock_pattern_autlock';
 update locksettings set value=1 where name='lockscreen.disabled';
 .quit

Source that made me edit my tables

Anton Kaiser
  • 713
  • 6
  • 11
4

Slightly modifying answer by @Yogeesh Seralathan. His answer works perfectly, just run these commands at once.

adb shell input keyevent 26 && adb shell input keyevent 82 && adb shell input text XXXX && adb shell input keyevent 66

// OR
adb shell input keyevent 26 && adb shell input touchscreen swipe 930 880 930 380 && adb shell input text XXXX && adb shell input keyevent 66

Where:
input Keyevent 26 denotes Power Button Pressed.
input touchscreen swipe 930 880 930 380 denotes Swipe Up.
input text XXXX denotes your Password entered.
input keyevent 66 denotes Enter key Pressed.

Junaid Pathan
  • 3,850
  • 1
  • 25
  • 47
  • Converted to useful alias => alias unlock="adb shell 'input keyevent 26 && input keyevent 82 && input text 12345678 && input keyevent 66'" – Alexey Dec 14 '22 at 08:47
2

If you want to open your phone without touching it here is the way

Steps

  1. Make sure you have completed the adb setup in both pc and android
  2. open cmd(Command Prompt)
  3. type adb devices to cheek if your phone is ready or not
  4. If it shows something like
List of devices attached
059c97f4        device

then enter the following command

adb shell input keyevent 26 && adb shell input swipe 600 600 0 0 && adb shell input text <pass> && adb shell input keyevent 66

put your password in <pass> and done. You phone is hopefully opened

  • Thanks! Although `adb shell input keyevent 26` causes a problem if the phone is already switched on (because then the command switches the phone off...). However, executing `adb shell input keyevent KEYCODE_MENU` instead... works whether if the phone is on or off :-) . Therefore, the resulting code that always works for me (even if a fingerprint is expected or the phone is switched off) is: `adb shell input keyevent KEYCODE_MENU && adb shell input swipe 600 600 0 0 && adb shell input text && adb shell input keyevent KEYCODE_ENTER` – Ganton Dec 05 '20 at 13:56
2

Building on @Bhaskar's answer and others, here's a full command to unlock (tested on Pixel 3):

adb shell input keyevent 26 && adb shell input keyevent 82 && adb shell input text <password> && adb shell input keyevent 66
Hunter Medney
  • 381
  • 2
  • 10
1

I would like to share my way, first of all i had Huawei ascend p7 and my touch screen stopped handling touch, so none of the above solutions helped me to be unlock the phone, i have found a better clever way to do it since i can see the screen on thus i thought that my display is 1080 x 1920 px thus i had to simulate a drawing on my photoshop with keypad with (x,y) so i can try instead with input mouse tap command.

screenshot of simulation

Since i have pin lock as you can see in the picture, i have got all the (x,y) for all the numbers on the screen to simulate touch and unlock my screen and have to backup my data, thus if my password is 123 i did all the following commands

adb shell input mouse tap 100 1150
adb shell input mouse tap 500 1150
adb shell input mouse tap 900 1150

And then my phone just got unlocked, i hope it was helpful.

AaoIi
  • 8,288
  • 6
  • 45
  • 87
1

Swipe unlock (works on Pixel 3a):

adb shell input keyevent 26 && adb shell input touchscreen swipe 2 4400 500 2
Kevin
  • 2,296
  • 21
  • 22
-1

I had found a particular case where swiping (ADB shell input touchscreen swipe ... ) to unlock the home screen doesn't work. More exactly for Acer Z160 and Acer S57. The phones are history but still, they need to be taken into consideration by us developers. Here is the code source that solved my problem. I had made my app to start with the device. and in the "onCreate" function I had changed temporarily the lock type.

Also, just in case google drive does something to the zip file I will post fragments of that code below.

AndroidManifest:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        package="com.example.gresanuemanuelvasi.test_wakeup">
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
        <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
        <application
            android:allowBackup="true"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/app_name"
            android:roundIcon="@mipmap/ic_launcher_round"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
            <activity android:name=".MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <receiver android:name=".ServiceStarter" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"
                android:directBootAware="true" tools:targetApi="n">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED"/>
                    <category android:name="android.intent.category.DEFAULT" />
                </intent-filter>
            </receiver>
        </application>
    </manifest>

    class ServiceStarter: BroadcastReceiver() {
        @SuppressLint("CommitPrefEdits")
        override fun onReceive(context: Context?, intent: Intent?) {
            Log.d("EMY_","Calling onReceive")
             context?.let {
                 Log.i("EMY_", "Received action: ${intent!!.getAction()}, user unlocked: " + UserManagerCompat.isUserUnlocked(context))

                 val sp =it.getSharedPreferences("EMY_", Context.MODE_PRIVATE)
                 sp.edit().putString(MainActivity.MY_KEY, "M-am activat asa cum trebuie!")

                 if (intent!!.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
                     val i = Intent(it, MainActivity::class.java)
                     i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                     it.startActivity(i)
                 }
            }
        }
    }

class MainActivity : AppCompatActivity() {

    companion object {
        const val MY_KEY="MY_KEY"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val kgm = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
        val kgl = kgm.newKeyguardLock(MainActivity::class.java.simpleName)
        if (kgm.inKeyguardRestrictedInputMode()) {
            kgl.disableKeyguard()
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(arrayOf(Manifest.permission.RECEIVE_BOOT_COMPLETED), 1234)
        }
        else
        {
            afisareRezultat()
        }
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {

        if(1234 == requestCode )
        {
            afisareRezultat()
        }

        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }

    private fun afisareRezultat() {
        Log.d("EMY_","Calling afisareRezultat")
        val sp = getSharedPreferences("EMY_", Context.MODE_PRIVATE);
        val raspuns = sp.getString(MY_KEY, "Doesn't exists")
        Log.d("EMY_", "AM primit: ${raspuns}")
        sp.edit().remove(MY_KEY).apply()
    }
}