Is there an android shell or adb command that I could use to get a device's IMEI/MEID?

后端 未结 8 926
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-03 02:44

Is there some adb or android shell command that I could run that would return a device\'s IMEI or MEID number? Preferably that\'s all that would be returned.

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 03:30

    As the iphonesubinfo 1 command does not work on many devices, here is a little workaround that should work consistently on most Android versions and on rooted and unrooted devices:

    If you already have an own app that you can install on the device that you want to know the IMEI from, add this BroadcastReceiver to your app:

    public class GetImeiReceiver extends BroadcastReceiver {
    
        @Override
        public void onReceive(Context context, Intent intent) {
            String imei = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
            setResultData(imei);
        }
    
    }
    

    and to the AndroidManifest.xml:

    
      
        
      
    
    

    Call your receiver over ADB:

    adb shell am broadcast -a com.myapp.GET_IMEI
    

    ...and the output will be something like:

    Broadcast completed: result=0, data="000000000000000"
    

    ...where data is the device IMEI.

    If you have don't have an existing app to integrate this solution into, I created this simple one which includes the required code: https://github.com/saschoar/android-imei-getter (also includes the APK and full instructions).

提交回复
热议问题