IT

Android 기기 이름 가져 오기

lottoking 2020. 5. 29. 08:14
반응형

Android 기기 이름 가져 오기 [중복]


이 질문에는 이미 답변이 있습니다.

안드로이드 장치 이름을 얻는 방법? HTC 욕망을 사용하고 있습니다. HTC 동기화를 통해 연결하면 소프트웨어에 'HTC Smith'라는 이름이 표시 됩니다. 코드를 통해이 이름을 가져오고 싶습니다.

안드로이드에서 어떻게 가능합니까?


Android 기기 이름을 얻으려면 한 줄의 코드 만 추가하면됩니다.

android.os.Build.MODEL;

여기에서 발견 : getting-android-device-name


여기에서 답변을 볼 수 있습니다. 프로그래밍 방식으로 Android 전화 모델 가져 오기

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 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);
    }
}

블루투스 이름을 가져 와서이 문제를 해결했지만 BluetoothAdapter(블루투스 권한이 필요한) 이름은 아닙니다 .

코드는 다음과 같습니다.

Settings.Secure.getString(getContentResolver(), "bluetooth_name");

추가 권한이 필요하지 않습니다.


시도 해봐. 블루투스를 통해 장치 이름을 얻을 수 있습니다.

그것이 당신을 도울 것입니다 희망

public String getPhoneName() {  
        BluetoothAdapter myDevice = BluetoothAdapter.getDefaultAdapter();
        String deviceName = myDevice.getName();     
        return deviceName;
    }

많은 인기있는 장치에서 장치의 시장 이름을 사용할 수 없습니다. 예를 들어, 삼성 갤럭시 S6에서의 값이 Build.MODEL될 수있다 "SM-G920F", "SM-G920I"또는 "SM-G920W8".

나는 장치의 시장 (소비자 친화적) 이름을 얻는 작은 라이브러리를 만들었습니다. 10,000 개가 넘는 장치 의 정확한 이름을 가져오고 지속적으로 업데이트됩니다. 내 라이브러리를 사용하려면 아래 링크를 클릭하십시오.

Github의 AndroidDeviceNames 라이브러리


위의 라이브러리를 사용하지 않으려면 소비자 친화적 인 장치 이름을 얻는 가장 좋은 솔루션입니다.

/** Returns the consumer friendly device name */
public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return capitalize(model);
    }
    return capitalize(manufacturer) + " " + model;
}

private static String capitalize(String str) {
    if (TextUtils.isEmpty(str)) {
        return str;
    }
    char[] arr = str.toCharArray();
    boolean capitalizeNext = true;
    String phrase = "";
    for (char c : arr) {
        if (capitalizeNext && Character.isLetter(c)) {
            phrase += Character.toUpperCase(c);
            capitalizeNext = false;
            continue;
        } else if (Character.isWhitespace(c)) {
            capitalizeNext = true;
        }
        phrase += c;
    }
    return phrase;
}


Verizon HTC One M8의 예 :

// using method from above
System.out.println(getDeviceName());
// Using https://github.com/jaredrummler/AndroidDeviceNames
System.out.println(DeviceName.getDeviceName());

결과:

HTC6525LVW

HTC 하나 (M8)


당신이 사용할 수있는:

안드로이드 문서에서 :

MANUFACTURER:

String MANUFACTURER

제품 / 하드웨어 제조업체.

MODEL:

String MODEL

최종 제품의 최종 사용자가 볼 수있는 이름입니다.

DEVICE:

String DEVICE

산업 디자인의 이름입니다.

예를 들어 :

String deviceName = android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL;
//to add to textview
TextView textView = (TextView) findViewById(R.id.text_view);
textView.setText(deviceName);

Furthermore, their is lot of attribute in Build class that you can use, like:

  • os.android.Build.BOARD
  • os.android.Build.BRAND
  • os.android.Build.BOOTLOADER
  • os.android.Build.DISPLAY
  • os.android.Build.CPU_ABI
  • os.android.Build.PRODUCT
  • os.android.Build.HARDWARE
  • os.android.Build.ID

Also their is other ways you can get device name without using Build class(through the bluetooth).


@hbhakhra's answer will do.

If you're interested in detailed explanation, it is useful to look into Android Compatibility Definition Document. (3.2.2 Build Parameters)

You will find:

DEVICE - A value chosen by the device implementer containing the development name or code name identifying the configuration of the hardware features and industrial design of the device. The value of this field MUST be encodable as 7-bit ASCII and match the regular expression “^[a-zA-Z0-9_-]+$”.

MODEL - A value chosen by the device implementer containing the name of the device as known to the end user. This SHOULD be the same name under which the device is marketed and sold to end users. There are no requirements on the specific format of this field, except that it MUST NOT be null or the empty string ("").

MANUFACTURER - The trade name of the Original Equipment Manufacturer (OEM) of the product. There are no requirements on the specific format of this field, except that it MUST NOT be null or the empty string ("").


Following works for me.

String deviceName = Settings.Global.getString(.getContentResolver(), Settings.Global.DEVICE_NAME);

I don't think so its duplicate answer. The above ppl are talking about Setting Secure, for me setting secure is giving null, if i use setting global it works. Thanks anyways.


UPDATE You could retrieve the device from buildprop easitly.

static String GetDeviceName() {
    Process p;
    String propvalue = "";
    try {
        p = new ProcessBuilder("/system/bin/getprop", "ro.semc.product.name").redirectErrorStream(true).start();
        BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            propvalue = line;
        }
        p.destroy();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return propvalue;
}

But keep in mind, this doesn't work on some devices.


Simply use

BluetoothAdapter.getDefaultAdapter().getName()


Try this code. You get android device name.

public static String getDeviceName() {
    String manufacturer = Build.MANUFACTURER;
    String model = Build.MODEL;
    if (model.startsWith(manufacturer)) {
        return model;
    }
    return manufacturer + " " + model;
}

 static String getDeviceName() {
        try {
            Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
            Method getMethod = systemPropertiesClass.getMethod("get", String.class);
            Object object = new Object();
            Object obj = getMethod.invoke(object, "ro.product.device");
            return (obj == null ? "" : (String) obj);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

enter image description here

you can get 'idol3' by this way.

참고URL : https://stackoverflow.com/questions/7071281/get-android-device-name

반응형