How to get IMEI using adb command on Android 13? - android

There is a question about Getting IMEI number using ADB commands Android 12.
adb root
adb shell "service call iphonesubinfo 1 i64 0 | cut -c 52-66 | tr -d '.[:space:]'"
I tested the method, and it works well on Android 12.
But from android 13 on, it just returns an error message: "Package does not belong to ..."
Does anyone can help? Thanks!

Below ADB command uses UIAutomator of Android.
Method: Call app -> *#06# -> Get value
adb shell "imei=$(input keyevent KEYCODE_WAKEUP;input keyevent KEYCODE_CALL;sleep 1;input text '*#06#'; uiautomator dump --compressed /dev/stdout|sed s/\>\<\/\\n/g|grep -A1 IMEI1|tail -n1|sed -e 's/.*text=\"//' -e 's/\".*//'); echo ${imei:0:16}"
You can edit to get IMEI1, IMEI2, SN. My phone is Samsung Galaxy, if you use other phone brands, edit it accordingly.
Note: Not work when your phone is locked

Related

adb cannot accurately read IMEI 1 and 2

there are two OPPO phones, using adb cannot accurately read IMEI 1 and 2, but only MEID. How can I read IMEI?
Android version 11 Model PEAM00 and PEMM20
Tried the following command, but it doesn't work, only MEID is returned.
adb shell service call iphonesubinfo 1
adb shell service call iphonesubinfo 2
Found in a different StackOverflow thread that I can't find now:
adb shell "service call iphonesubinfo 1 | cut -c 52-66 | tr -d '.[:space:]'"
This is working on Android 11. If it's not working straight from CMD then type
adb shell
and then the rest of the command (service call ...)

Get IMEI via ADB only for old Huawei models

I need a bit of assistance. I have a Huawei g6-l11 (with Android 4.3) from which I am trying to extract the IMEI via ADB. I know that this device is ancient, but this is one of my tasks. So far I had tried everything I could find on the internet, like:
1) adb shell getprop | grep "<IMEI>"
2) adb shell service call iphonesubinfo N | grep "<IMEI>" - Where N is a number between 1 and 50
3) adb shell settings get secure android_id
4) adb shell content query --uri content://settings/secure | grep "<IMEI>"
5) adb shell content query --uri content://settings/system | grep "<IMEI>"
6) adb shell content query --uri content://settings/global | grep "<IMEI>"
7) adb shell dumpsys | grep "<IMEI>"
So I had made an Android app and run this piece of code on the smartphone:
val tm = this.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
Log.d("Emy_","The IMEI is ${tm.deviceId}")
That worked fine but it is an Android app when I need to do the same thing but only via ADB.
Also, I had found a fastboot command that would help me (like: fastboot oem get-psid). But the problem is that I need to reboot the phone into fast boot mode. Which is taking too long.
My questions are:
1) why is it different for Huawei models with the OS version below Marshmallow to extract the IMEI?
2) how could I replicate the function call done by the Java code to be done with the ADB in the terminal? Or in other words, what other commands would you recommend to me to try to extract the IMEI?
You could display it on screen:
adb am start -a android.intent.action.CALL -d tel:*%2306%23
If you just searching to know the IMEI, You can try this code : *#06#
Or you can try this : adb shell
service call iphonesubinfo 1 | toybox cut -d "'" -f2 | toybox grep -Eo '[0-9]' | toybox xargs | toybox sed 's/\ //g'
hop that help you !

Reboot to Bootloader with shell script to multiple devices hangs if more than one device attached

Full disclosure: I'm new to both Android development and Linux.
I have a shell script to loop through connected devices and perform ADB commands.
while read -r udid device usb product model device2; do
echo ""
echo $usb
echo ""
# REBOOT
adb -s "$usb" reboot-bootloader
# UNLOCK OEM
fastboot -s "$usb" oem unlock
# REBOOT
fastboot -s "$usb" reboot
done < <(adb devices -l | sed "1d; $ d")
This works great on one device. If I have two devices the first device will work but the second will hang at:
< waiting for usb:1-2 >
On three devices the first device will reboot to bootloader and then hang like I said above.
The endgame here is to execute this script (and several others) on as many android devices as possible at one time. This loop works great for pushing our APK to each device but to unlock the bootloader, to run this code AND for another script to boot to recovery it hangs.
I found this stackoverflow and made sure my udev rules were correct. As I said it works on one device no problem.
I also referenced this post that recommended I change my while loop to a for loop and that has the same result.
These devices are Mediatek phones running Android 6.0 Marshmallow. So all the serial number are the same (0123456789ABCDEF) if that's an issue. I'm using Ubuntu 8.10.
So I ended up not using linux and the issue was with the devices all having the same serial number. What I did do was create to bash scripts to run on PC.
The first script looped through the device by the TRANSIT ID to apply the second script which was full of adb commands.
EXAMPLE:
SCRIPT 1:
#echo off
cd C:\adb
FOR /f "tokens=5 delims=:" %%G IN ('adb devices -l') DO (
start cmd.exe /c "call c:\srcmd\esc-cmd.bat %%G"
)
Calls SCRIPT 2:
#echo off
cd C:\adb
echo ##OPEN AND INSTALL SETTINGS APP##
echo ""
echo ""
echo ""
adb -t %~1 shell input keyevent KEYCODE_WAKEUP
adb -t %~1 shell input keyevent 111
echo ""
echo ""
echo ""
echo ##DONE##
With this system I can run custom adb scripts on multiple devices at one time. I'm running up to 20 at a time at the moment. Works like a charm!

Check if adb device connected condition

How can I check adb device is connected in batch files?
I wrote "adb devices" in the batch file, but I want it as a condition so the app working smoothly and automatically
So if the user is not connected his device print no device and exit the app,
Otherwise resume the app.
Pipe the output to find and analyse the errorlevel:
adb devices -l | find "device product:" >nul
if errorlevel 1 (
echo No connected devices
) else (
echo Found!
..............
)
For user in bash or similar shell environment, try
$ adb get-state 1>/dev/null 2>&1 && echo 'device attached' || echo 'no device attached'
This is the easiest and is most accurate since it'll only find "device" and not other words containing the string such as "devices":
adb devices | findstr "\<device\>"
Take note that findstr works on Windows but not in Unix terminals. So the equivilent would be to use find and grep together. John explains this well in this page Using find and grep to Mimic findstr Command

Can I use adb.exe to find a description of a phone?

If I call the command "adb.exe devices" I get a list of devices with a unique ID for each. These IDs are perfect for programming but not very human readable. Is there any way I can link one of these IDs to a (not necessarily unique) description of the phone? For example, if I have a device with an ID 1234567890abcdef is there any way I can figure that in real life it is a Motorola Droid X?
In Android there is a Model number entry in settings that shows phone name.
There is a way to quickly see this via command line:
adb shell cat /system/build.prop | grep "product"
This is what's shown for Samsung Galaxy S 4G:
ro.product.model=SGH-T959V
ro.product.brand=TMOUS
ro.product.name=SGH-T959V
ro.product.device=SGH-T959V
ro.product.board=SGH-T959V
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.manufacturer=Samsung
ro.product.locale.language=en
ro.product.locale.region=US
# ro.build.product is obsolete; use ro.product.device
ro.build.product=SGH-T959V
On a HTC Desire, the output looks like this:
ro.product.model=HTC Desire
ro.product.brand=htc_wwe
ro.product.name=htc_bravo
ro.product.device=bravo
ro.product.board=bravo
ro.product.cpu.abi=armeabi-v7a
ro.product.cpu.abi2=armeabi
ro.product.manufacturer=HTC
ro.product.locale.language=hdpi
ro.product.locale.region=
You can refine your query to show only one line:
adb shell cat /system/build.prop | grep "ro.product.device"
or
adb shell cat /system/build.prop | grep "ro.product.model"
With newer devices, you can run
adb devices -l
This will list some devices in a more human readable form
Example:
04d9a601ce516d53 device usb:1A134500 product:occam model:Nexus_4 device:mako
015d4b3406280a07 device usb:1A134700 product:nakasi model:Nexus_7 device:grouper
01466E620900F005 device usb:1A134600 product:mysid model:Galaxy_Nexus device:toro
Yes, adb shell cat /system/build.prop is wonderful, but also as #Matt said, it sometimes differs because of different manufacture.
IMHO, the most reliable approach is the built-in command: adb shell getprop
======================================================================
Here is a comparison for an exception (Genymotion emulator):
By adb shell cat /system/build.prop you'll get
ro.product.brand=generic
ro.product.name=vbox86p
ro.product.device=vbox86p
ro.product.board=
ro.product.cpu.abi=x86
ro.product.manufacturer=Genymotion
ro.product.locale.language=en
ro.product.locale.region=US
So there is no model value :(
By adb shell getprop you'll get
[ro.product.manufacturer]: [Genymotion]
[ro.product.model]: [Nexus422ForAutomation]
[ro.product.name]: [vbox86p]
Here you get the model name: Nexus422ForAutomation :)
Unfortunately, there is no reliable way to do this since each manufacturer tweaks their build properties
If you type "adb help" into the command line you can see a list of the adb commands and a description for each.
I'm using this script (on MacOS):
#!/bin/bash
devices=`adb devices | grep "device" | grep -v "List of" | cut -d " " -f 1`
for device in $devices
do
manufacturer=`adb -s $device shell getprop ro.product.manufacturer | sed -e 's/[[:space:]]*\$//'`
model=`adb -s $device shell getprop ro.product.model | sed -e 's/[[:space:]]*\$//'`
echo "$device: $manufacturer $model"
done
It produces e.g. the following output:
T076000UWX: motorola XT1053
C4F12070E5A068E: samsung GT-P7510
4df1ff977b919f91: samsung GT-N7100
4258393032523638324D: Sony Ericsson LT18i

Categories

Resources