adb is a command line program for Windows, Mac, and Linux, it is part of the SDK platform-tools, and can be used for a variety of functions. Using it may seem daunting at first for those unfamiliar with command line
Setting up adb
Phone part:
- First head over to the settings app, the about section at the bottom- tap the 'build number' until developer mode is unlocked
- go to system settings, developer options
- scroll down and enable USB debugging, now you can start the PC part
When an adb server is running while the device is connected via USB, a prompt will appear asking if you want to give the server USB debugging permission.
Demonstration:
PC part:
- Download and unzip the latest SDK platform-tools from Android.com (I use Windows 11)
- Once you go inside the folder, right-click a blank space in the folder and select Terminal
Note: You may have to hold shift on the keyboard while right clicking, additionally it may say 'Command Prompt' or 'PowerShell' both of which will work
- adb devices
This command will start an adb.exe daemon (server) on your PC and list connected devices it sees, at this point a prompt should appear on your Android device asking to trust this PC
- adb kill-server
This stops the server, it isn't a problem if you forget to run this once you finish, when you restart/shutdown the PC, the server doesn't automatically restart
Copy an apk from Phone to PC
- adb shell pm list packages -f | adb shell grep kde
- 'adb shell pm list packages' will list all currently installed packages on the phone
- '-f' appended to the end will show the path of the packages in addition to their names, (see also optional 1)
- '| adb shell grep kde' isn't actually necessary, it is filtering the long list. In this case I choose kde to search for the KDE Connect package I installed, you can replace that with 'camera' for example and it would show the name of all installed camera packages - adb pull /data/app/~~75t6zHxPXKoKDa2PhiL2lQ==/org.kde.kdeconnect_tp-6VHvQ24bgrY6tnRyrH8WYw==/base.apk kde.apk
- 'adb pull [source] [destination]' The source is the path of the package on the phone, everything after the first colon (:) up to and including the first (.apk).
the destination is the folder where you opened the terminal with the right-click above, you can name it whatever you want, in this case I choose kde.apk
optional 1 - list package path separately
- adb shell pm list packages | adb shell grep kde
Similar to above, this will list all installed packages, and use your phones grep to filter the list to just the given string, in this case 'kde' - adb shell pm path org.kde.kdeconnect_tp
- 'adb shell pm path' Given a package name, this will return the path of that package
Install/Uninstall an apk using adb
- adb shell pm list users
Android supports multiple user, I use it to separate my finance related apps from everything else, the primary user typically has the id of 0 - adb install --user 0 com.simplemobiletools.calculator_56.apk
- `'adb install --user 0' explicitly installs the app to just user 0, the default user
- 'com.simplemobiletools.calculator_56.apk' is the name of the apk stored on my PC that will be installed on the phone
- adb uninstall --user 0 com.simplemobiletools.calculator
- `'adb uninstall --user 0' similar to above, uninstalls from just user 0
- 'com.simplemobiletools.calculator' when uninstalling an apk, the version number isn't used nor the '.apk'
(Note: Highlighted two separate phones between the first and second 'list users' commands to emphasize default id's being 0)
Other
- adb shell pm install-existing --user 12 com.simplemobiletools.calculator
This will enable a previously disabled app, but also can be combined with --user <id> to install an package from one user account to another, without the need to pull it off the device first
Comments
Displaying 0 of 0 comments ( View all | Add Comment )