GVKun编程网logo

Android 获得手机ip地址(android获取手机ip地址)

9

想了解Android获得手机ip地址的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于android获取手机ip地址的相关问题,此外,我们还将为您介绍关于AndroidAPN设置及获得手机号、

想了解Android 获得手机ip地址的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于android获取手机ip地址的相关问题,此外,我们还将为您介绍关于Android APN设置及获得手机号、android – 如何从IP地址解析网络主机名、android – 如何获得手机用户的名字(或全名)?、android – 我怎样才能获得手机的ICCID号码?的新知识。

本文目录一览:

Android 获得手机ip地址(android获取手机ip地址)

Android 获得手机ip地址(android获取手机ip地址)

下面是小编 jb51.cc 通过网络收集整理的代码片段。

小编小编现在分享给大家,也给大家做个参考。

public String getLocalIpAddress() { 
 
        try {  
            for (Enumeration<NetworkInterface> en = NetworkInterface 
                   .getNetworkInterfaces(); 
   
            en.hasMoreElements();) { 
  
               NetworkInterface intf = en.nextElement(); 
   
                for (Enumeration<InetAddress> enumIpAddr = intf 
                        .getInetAddresses();   
               enumIpAddr.hasMoreElements();) { 
                     InetAddress inetAddress = enumIpAddr.nextElement(); 
   
                    if (!inetAddress.isLoopbackAddress()) { 
   
                        return inetAddress.getHostAddress().toString(); 
   
                    } 
   
                } 
   
            } 
   
        } catch (SocketException ex) { 
       } 
   
        return null; 
   
    }  

以上是小编(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给程序员好友。

Android APN设置及获得手机号

Android APN设置及获得手机号

目前供职于电信,只做电信的业务,故列表中只有电信的APN信息

  /**
  * 电信APN列表
  * @author wudongdong
  *
  */

  public class APNNET {

  public static String CTWAP="ctwap";
  public static String CTNET="ctnet";

  }

获得APN的类型

  /**
  * 获得APN类型
  * @author wudongdong
  *
  */

  public class ApnUtil {

  private static Uri PREFERRED_APN_URI = Uri

  .parse("content://telephony/carriers/preferapn");

  /**
  * get apntype
  * @param context
  * @return
  */

  public static String getApnType(Context context){

  String apntype="nomatch";

  Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,

  null, null, null, null);

  c.moveToFirst();

  String user=c.getString(c.getColumnIndex("user"));

  if(user.startsWith(APNNET.CTNET)){

  apntype=APNNET.CTNET;

  }else if(user.startsWith(APNNET.CTWAP)){

  apntype=APNNET.CTWAP;

  }

  return apntype;

  }

  }

获得手机号码的话可以传IMSI码到指定接口,接口地址不方便说。

但可以透露一点,必须走CTWAP,这也是判断APN类型的原因

发现很多应用如果APN是走代理的话就不能联网,那么再介绍一下用APN设置网络的代理信息。

  Cursor c = context.getContentResolver().query(PREFERRED_APN_URI,

  null, null, null, null);

  c.moveToFirst();

  String proxy=c.getString(c.getColumnIndex("proxy"));

  if (!"".equals(proxy) && proxy!=null) {

  Properties prop = System.getProperties();

  System.getProperties().put("proxySet", "true");

  prop.setProperty("http.proxyHost", c.getString(c

  .getColumnIndex("proxy")));

  prop.setProperty("http.proxyPort", c.getString(c

  .getColumnIndex("port")));

  String authentication = c.getString(c.getColumnIndex("user"))

  + ":" + c.getString(c.getColumnIndex("password"));

  String encodedLogin = Base64.encode(authentication);

  uc.setRequestProperty("Proxy-Authorization", " BASIC "

  + encodedLogin);

  }

  c.close();

android – 如何从IP地址解析网络主机名

android – 如何从IP地址解析网络主机名

我正在研究基于wifi的聊天引擎,我能够通过跟随this链接检索连接到当前wifi网络的主机列表,现在获得了具有ip地址的设备列表但我需要来自ip地址的主机名并尝试以下

InetAddress inetAddr;
try {
    inetAddr = InetAddress.getByName(host.hostname);
    String hostname = inetAddr.getHostName();
    String canonicalHostname = inetAddr.getCanonicalHostName();
    holder.computerName.setText("Canonical : "+host.hostname);
} catch (Exception e) {
    e.printstacktrace();
}

这里主机名和规范主机名都显示ip地址而不是主机名.

请帮我解决这个问题.

解决方法:

我想你可以这样做:

try {
  Log.d("ReversednS", "Reverse DNS for 8.8.8.8 is: " + InetAddress.getByName("8.8.8.8").getHostName());
} catch (UnkNownHostException e) {
  Log.e("ReversednS", "Oh no, 8.8.8.8 has no reverse DNS record!");
}

一些额外的东西:

>考虑到这是一个可能需要很长时间的操作(理解为长时间几秒),因此绝对建议在Thread或AsyncTask中完成.
>除响应时间外,这是一个网络操作,因此您需要在UI线程之外执行此操作.
>还要记住,每个主机都有一个关联的IP地址,但并非每个IP地址都有一个反向主机,因此操作可能会失败,您也需要处理它.
>您要查询的DNS服务器是您的提供商之一(或者如果您计划在不同客户端中运行此服务提供商,则为客户提供商).这意味着并非每个结果都是一样的.例如,您的DNS服务器可能无法解析IP的反向主机,而其他DNS服务器可能无法解析.

android – 如何获得手机用户的名字(或全名)?

android – 如何获得手机用户的名字(或全名)?

有没有办法获得用户的名字或全名?我的意思是电话的用户

它需要特殊的清单权限吗?

解决方法:

是的,从ICS开始,您可以读取设备所有者的配置文件(需要READ_PROFILE权限):

http://developer.android.com/reference/android/provider/ContactsContract.Profile.html

具体来说,disPLAY_NAME列应该有自己的名字.或者,您可以查找Structuredname数据项以获取其GIVEN_NAME:

http://developer.android.com/reference/android/provider/ContactsContract.CommonDataKinds.StructuredName.html

android – 我怎样才能获得手机的ICCID号码?

android – 我怎样才能获得手机的ICCID号码?

我怎样才能获得手机的iccid号码?

我查看了TelephonyManager类,但没有找到获取iccid编号​​的方法,只有一种方法可以告诉ICC卡是否存在.

解决方法:

我相信getSimSerialNumber()会变得微不足道.

今天关于Android 获得手机ip地址android获取手机ip地址的分享就到这里,希望大家有所收获,若想了解更多关于Android APN设置及获得手机号、android – 如何从IP地址解析网络主机名、android – 如何获得手机用户的名字(或全名)?、android – 我怎样才能获得手机的ICCID号码?等相关知识,可以在本站进行查询。

本文标签: