Android: How to get current device WiFi-direct name

前端 未结 3 1607
情深已故
情深已故 2021-01-04 13:53

In a P2P setting, I understand how to get another device\'s name, but how do I get my own device\'s name? (the one displayed in WiFi-direct under settings).

I have c

3条回答
  •  太阳男子
    2021-01-04 14:37

    Try this code:

    public static String getHostName(String defValue) {
        try {
            Method getString = Build.class.getDeclaredMethod("getString", String.class);
            getString.setAccessible(true);
            return getString.invoke(null, "net.hostname").toString();
        } catch (Exception ex) {
            return defValue;
        }
    }
    

提交回复
热议问题