how to get the android phone model, version, sdk details?

前端 未结 5 2044
感情败类
感情败类 2021-01-30 11:03

how to get the android phone model, version, sdk details?

5条回答
  •  攒了一身酷
    2021-01-30 11:26

    // Getting Device Model,Manufacturer,android os version and device id:

    public String getDeviceName() {
    
        String manufacturer = Build.MANUFACTURER;
        String model = Build.MODEL;
    
        if (model.startsWith(manufacturer)) {
            return capitalize(model);
        } else {
            return capitalize(manufacturer) + " " + model;
        }
    }
    
    private String getAndroidVersion() {
        return android.os.Build.VERSION.RELEASE;
    }
    
    private String capitalize(String s) {
        if (s == null || s.length() == 0) {
            return "";
        }
        char first = s.charAt(0);
        if (Character.isUpperCase(first)) {
            return s;
        } else {
            return Character.toUpperCase(first) + s.substring(1);
        }
    }
    
    private String getDeviceId() {
        String deviceId = "";
        final TelephonyManager mTelephony = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        if (mTelephony.getDeviceId() != null) {
            deviceId = mTelephony.getDeviceId();
        } else {
            deviceId = Secure.getString(getApplicationContext()
                    .getContentResolver(), Secure.ANDROID_ID);
        }
        return deviceId;
    }
    

提交回复
热议问题