How to get my android device name in my android programe?

∥☆過路亽.° 提交于 2019-12-12 09:53:58

问题


I get device names by the command "adb deivces" in command line. Now I want get name in my android device.

  String serial = null;     
    try {         
        Class<?> c = Class.forName("android.os.SystemProperties");    
        Method get = c.getMethod("get", String.class);   
        serial = (String) get.invoke(c, "ro.serialno");  
        System.out.println(serial);
        } 
    catch (Exception ignored) {  

    }

those works fine in my android phone.But my acer a500 tablet gets the real serial number. This is not correspond with the name I get from the adb command.

I surpose the ddms gets the devices name by another method. But i dont know.


回答1:


getting-android-device-name i do hope this link may help you.

TextView tv1 = (TextView) findViewById(R.id.tv1);

String str = android.os.Build.MODEL;

tv1.setText(str);




回答2:


android.os.Build contains device info. You're probably interested in Build.MODEL




回答3:


Did you try

android.os.Build.MANUFACTURER



回答4:


Just to further elaborate: Build.MODEL is a string which is the shortened version of android.os.Build.MODEL.

so String text = ("Build model " + Build.MODEL); results in text such as "SCH-I545" for newer phones or "Galaxy Nexus" for older phones. Depends on manufacturer and OS version.



来源:https://stackoverflow.com/questions/7253938/how-to-get-my-android-device-name-in-my-android-programe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!