类 DeviceUtils


  • public final class DeviceUtils
    extends java.lang.Object
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static DeviceUtils.CommandResult execCmd​(java.lang.String[] commands, boolean isRooted, boolean isNeedResultMsg)  
      static DeviceUtils.CommandResult execCmd​(java.lang.String[] commands, java.lang.String[] envp, boolean isRooted, boolean isNeedResultMsg)  
      static DeviceUtils.CommandResult execCmd​(java.lang.String command, boolean isRooted)  
      static java.lang.String[] getABIs()
      Return an ordered list of ABIs supported by this device.
      static java.lang.String getAndroidID​(android.content.Context context)
      Return the android id of device.
      static java.lang.String getMacAddress​(android.content.Context context)
      Return the MAC address.
      static java.lang.String getMacAddress​(android.content.Context context, java.lang.String... excepts)
      Return the MAC address.
      static java.lang.String getManufacturer()
      Return the manufacturer of the product/hardware.
      static java.lang.String getModel()
      Return the model of device.
      static int getSDKVersionCode()
      Return version code of device's system.
      static java.lang.String getSDKVersionName()
      Return the version name of device's system.
      static java.lang.String getString​(android.content.Context context, java.lang.String key, java.lang.String defaultValue)  
      static java.lang.String getUniqueDeviceId​(android.content.Context context)
      Return the unique device id.
      static java.lang.String getUniqueDeviceId​(android.content.Context context, boolean useCache)
      Return the unique device id.
      static java.lang.String getUniqueDeviceId​(android.content.Context context, java.lang.String prefix)
      Return the unique device id.
      static java.lang.String getUniqueDeviceId​(android.content.Context context, java.lang.String prefix, boolean useCache)
      Return the unique device id.
      static boolean isAdbEnabled​(android.content.Context context)
      Return whether ADB is enabled.
      static boolean isDevelopmentSettingsEnabled​(android.content.Context context)
      Whether user has enabled development settings.
      static boolean isDeviceRooted()
      Return whether device is rooted.
      static boolean isEmulator​(android.content.Context context)
      Return whether device is emulator.
      static boolean isSameDevice​(android.content.Context context, java.lang.String uniqueDeviceId)  
      static boolean isTablet()
      Return whether device is tablet.
      static void put​(android.content.Context context, java.lang.String key, java.lang.String value)  
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • isDeviceRooted

        public static boolean isDeviceRooted()
        Return whether device is rooted.
        返回:
        true: yes
        false: no
      • isAdbEnabled

        @RequiresApi(api=17)
        public static boolean isAdbEnabled​(android.content.Context context)
        Return whether ADB is enabled.
        返回:
        true: yes
        false: no
      • getSDKVersionName

        public static java.lang.String getSDKVersionName()
        Return the version name of device's system.
        返回:
        the version name of device's system
      • getSDKVersionCode

        public static int getSDKVersionCode()
        Return version code of device's system.
        返回:
        version code of device's system
      • getAndroidID

        public static java.lang.String getAndroidID​(android.content.Context context)
        Return the android id of device.
        返回:
        the android id of device
      • getMacAddress

        @RequiresPermission(allOf={"android.permission.ACCESS_WIFI_STATE","android.permission.CHANGE_WIFI_STATE"})
        public static java.lang.String getMacAddress​(android.content.Context context)
        Return the MAC address.

        Must hold <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />, <uses-permission android:name="android.permission.INTERNET" />, <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

        返回:
        the MAC address
      • getMacAddress

        @RequiresPermission(allOf="android.permission.ACCESS_WIFI_STATE")
        public static java.lang.String getMacAddress​(android.content.Context context,
                                                     java.lang.String... excepts)
        Return the MAC address.

        Must hold <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />, <uses-permission android:name="android.permission.INTERNET" />

        返回:
        the MAC address
      • getManufacturer

        public static java.lang.String getManufacturer()
        Return the manufacturer of the product/hardware.

        e.g. Xiaomi

        返回:
        the manufacturer of the product/hardware
      • getModel

        public static java.lang.String getModel()
        Return the model of device.

        e.g. MI2SC

        返回:
        the model of device
      • getABIs

        public static java.lang.String[] getABIs()
        Return an ordered list of ABIs supported by this device. The most preferred ABI is the first element in the list.
        返回:
        an ordered list of ABIs supported by this device
      • isTablet

        public static boolean isTablet()
        Return whether device is tablet.
        返回:
        true: yes
        false: no
      • isEmulator

        public static boolean isEmulator​(android.content.Context context)
        Return whether device is emulator.
        返回:
        true: yes
        false: no
      • isDevelopmentSettingsEnabled

        @RequiresApi(api=17)
        public static boolean isDevelopmentSettingsEnabled​(android.content.Context context)
        Whether user has enabled development settings.
        返回:
        whether user has enabled development settings.
      • getUniqueDeviceId

        public static java.lang.String getUniqueDeviceId​(android.content.Context context)
        Return the unique device id.
        {1}{UUID(macAddress)}
        {2}{UUID(androidId )}
        {9}{UUID(random    )}
        返回:
        the unique device id
      • getUniqueDeviceId

        public static java.lang.String getUniqueDeviceId​(android.content.Context context,
                                                         java.lang.String prefix)
        Return the unique device id.
        android 10 deprecated {prefix}{1}{UUID(macAddress)}
        {prefix}{2}{UUID(androidId )}
        {prefix}{9}{UUID(random    )}
        参数:
        prefix - The prefix of the unique device id.
        返回:
        the unique device id
      • getUniqueDeviceId

        public static java.lang.String getUniqueDeviceId​(android.content.Context context,
                                                         boolean useCache)
        Return the unique device id.
        {1}{UUID(macAddress)}
        {2}{UUID(androidId )}
        {9}{UUID(random    )}
        参数:
        useCache - True to use cache, false otherwise.
        返回:
        the unique device id
      • getUniqueDeviceId

        public static java.lang.String getUniqueDeviceId​(android.content.Context context,
                                                         java.lang.String prefix,
                                                         boolean useCache)
        Return the unique device id.
        android 10 deprecated {prefix}{1}{UUID(macAddress)}
        {prefix}{2}{UUID(androidId )}
        {prefix}{9}{UUID(random    )}
        参数:
        prefix - The prefix of the unique device id.
        useCache - True to use cache, false otherwise.
        返回:
        the unique device id
      • isSameDevice

        @RequiresPermission(allOf={"android.permission.ACCESS_WIFI_STATE","android.permission.INTERNET","android.permission.CHANGE_WIFI_STATE"})
        public static boolean isSameDevice​(android.content.Context context,
                                           java.lang.String uniqueDeviceId)
      • getString

        public static java.lang.String getString​(android.content.Context context,
                                                 @NonNull
                                                 java.lang.String key,
                                                 java.lang.String defaultValue)
      • put

        public static void put​(android.content.Context context,
                               @NonNull
                               java.lang.String key,
                               java.lang.String value)
      • execCmd

        public static DeviceUtils.CommandResult execCmd​(java.lang.String[] commands,
                                                        boolean isRooted,
                                                        boolean isNeedResultMsg)
      • execCmd

        public static DeviceUtils.CommandResult execCmd​(java.lang.String[] commands,
                                                        java.lang.String[] envp,
                                                        boolean isRooted,
                                                        boolean isNeedResultMsg)