这个依赖sim卡,但是,不是所有的sim卡都内置手机号码了。
所以就不要用手机号码,除非你和运营商合作。

解决方案 »

  1.   

    获取IMSI是一样的,唯一值,并且运营商也是通过IMSI来匹配号码的
      

  2.   

    唉,高兴早了,还是获取不到手机号码
    手机端代码
     public String getNativePhoneNumber(Context context) throws Exception { 
    //  String NativePhoneNumber=null; 
    //  NativePhoneNumber=telephonyManager.getLine1Number(); 
    //  return NativePhoneNumber; 

             String result = "";  
    //         String urlStr = "http://tv.ruyi.com/portal";  
             String urlStr = "http://XX.XX.XX.XX:XXXX/live/index.jsp";  
               
             Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));//联通CTWAP代理地址是10.0.0.172  
             URL url = new URL(urlStr);  
             HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);  
     
             if (conn == null){  
                 throw new IOException("URLConnection instance is null");  
             }  
     
             conn.setConnectTimeout(30000);//   
             conn.setDoOutput(true); // 发送POST请求必须设置允许输出,表示允许对外输出  
             conn.setUseCaches(false); // 不使用Cache  
             conn.setRequestMethod("GET");  
     
             conn.setRequestProperty("Accept", "*/*");  
             conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接  
             conn.setRequestProperty("Charset", "UTF-8");  
             conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");  
               
             int responseCode = conn.getResponseCode();  
             Log.e("IndexActivity","responseCode is:"+responseCode);  
             if(responseCode == 200){  
                 InputStream stream = conn.getInputStream();  
                 result = inStream2String(stream);  
                 
                 String temvit = result;
                 Log.e("error","result" + result);
                 if (temvit.substring(0, 3).trim().equals("861")||temvit.substring(0, 3).trim()=="861") {//此处视情况而定
                  result = temvit.substring(2, 13);
                    }
                    if (temvit.substring(0, 1).trim().equals("1")||temvit.substring(0, 1).trim()=="1") {//此处也是,视情况修改
                     result = temvit;
                    }
                    Log.e("error","result" + result);
             }else{  
                   Log.e("error","false");
             }  
             
    //         HttpClient client=new DefaultHttpClient(); 
    //         HttpPost request; 
    //         
    //         request = new HttpPost(new URI(urlStr)); 
    //         HttpResponse response = client.execute(request); 
    //         //判断请求是否成功 
    //         if(response.getStatusLine().getStatusCode()==200){ 
    //         HttpEntity entity=response.getEntity(); 
    //         if(entity!=null){ 
    //         result = EntityUtils.toString(entity); //返回获取的值 
    //         Log.e("error","result" + result);
    //         } else{ 
    //          result = "没有获取到任何数据!"; //返回空 
    //          Log.e("error","result" + result);
    //         } 
    //         }
    //         Log.e("error","result" + result);
             return result;  
            
     }网页代码Enumeration headers = request.getHeaderNames() ;
    while(headers.hasMoreElements())
    {
         String head = (String)headers.nextElement();
         out.println(head+":"+request.getHeader(head));
     //    String mobile = request.getParameter("HTTP_X_UP_CALLING_LINE_ID");
      //   out.println("HTTP_X_UP_CALLING_LINE_ID"+":"+mobile);
    }
    但是获取不到HTTP_X_UP_CALLING_LINE_ID对应的值啊,是null
    都能获取到手机型号信息,搞不明白为什么获取不到手机号,网页是放在联通提供的服务器上面的,是不是要做什么特殊的处理啊,应该不是简单的放在他们服务器上面就ok了。不知道页面上是不是要写一些调用联通接口的代码神马的啊
      

  3.   

    accept:*/*
    charset:UTF-8
    content-type:text/xml; charset=UTF-8
    user-agent:Dalvik/1.4.0 (Linux; U; Android 2.3.4; GT-S5570 Build/GINGERBREAD)
    host:10.82.52.16:8090
    accept-encoding:gzip
    cookie:
    connection:close
     HTTP_X_UP_CALLING_LINE_ID:null
    这是访问页面输出的结果,手机的型号都能获取到,为什么手机号没呢
      

  4.   

    请问怎么通过联通的wap接入,需要哪些东西,谢谢
      

  5.   

    Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("10.0.0.172",80));//联通CTWAP代理地址是10.0.0.172   
      URL url = new URL(urlStr);   
      HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);   
    这不是通过联通的wap接入的吗
      

  6.   


    "10.0.0.172",80这个是3G wap这个是联通3G卡连接上网的接入点的地址和端口,需要访问的页面只有手机端通过这个接入点连接上网才能访问到要访问的页面
      

  7.   

    郁闷,联通讲他们没有什么所谓的白名单
    大家帮我看看我这结果,是不是解析的有问题啊
    accept:*/*
    charset:UTF-8
    content-type:text/xml; charset=UTF-8
    user-agent:Dalvik/1.4.0 (Linux; U; Android 2.3.4; GT-S5570 Build/GINGERBREAD)
    host:XX.XX.XX.XX:XXXX
    accept-encoding:gzip
    cookie:
    connection:close
      

  8.   

    我们之前也大概了解过,好像不是所有的sim卡都可以获取它的号码的...
      

  9.   


    你手机设置wap访问试试。
      

  10.   

    HTTP_X_UP_CALLING_LINE_ID:null是这个选项,你手机浏览器访问试试。
      

  11.   

    我记得是取不到手机号的,只能取到sim卡的一个唯一标识号
      

  12.   

    我是用手机浏览器访问的啊,设置wap了,没有,HTTP_X_UP_CALLING_LINE_ID:null是这个结果,问了一下别人,首先不能漫游,就是当地的手机在该地区访问,还有访问的地址端口号必须是80,联通做了限制,这两个就没有办法了
      

  13.   

    问题解决了,是因为服务器和80端口的原因,必须是联通3gwap,方法奉上,仅供参考 public String getNativePhoneNumber(Context context) throws Exception { 
             String result = "";  
             String urlStr = "http://v.17186.cn/test.jsp";
             Proxy proxy = new Proxy(java.net.Proxy.Type.HTTP, new   InetSocketAddress("10.0.0.172",80));//联通CTWAP代理地址是10.0.0.172  
             URL url = new URL(urlStr);  
             HttpURLConnection conn=(HttpURLConnection) url.openConnection(proxy);  
             if (conn == null){  
                 throw new IOException("URLConnection instance is null");  
             }  
             conn.setConnectTimeout(30000);//   
             conn.setDoOutput(true); // 发送POST请求必须设置允许输出,表示允许对外输出  
             conn.setUseCaches(false); // 不使用Cache  
             conn.setRequestMethod("GET");  
             conn.setRequestProperty("Accept", "*/*");  
             conn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接  
             conn.setRequestProperty("Charset", "UTF-8");  
             conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");  
               
             int responseCode = conn.getResponseCode();  
             Log.e("IndexActivity","responseCode is:"+responseCode);  
             if(responseCode == 200){  
                 InputStream stream = conn.getInputStream();  
    //           stream = new GZIPInputStream(stream);
                 result = inStream2String(stream);  
                 String temvit = result;
                 //Log.e("error","result" + result);
                 int x = temvit.indexOf("<body>");
                 temvit = temvit.substring(x);
                 result = temvit.substring(7,24).trim();
                 Log.e("error","result: " + result);              
             }
             return result;  
     }
     public   String   inStream2String   (InputStream   in)   throws   IOException   { 
         StringBuffer   out   =   new   StringBuffer(); 
         byte[]   b   =   new   byte[4096]; 
         for   (int   n;   (n   =   in.read(b))   !=   -1;)   { 
                 out.append(new   String(b,   0,   n)); 
         } 
         return   out.toString(); 
    }
      

  14.   

    项目源码下载地址 http://download.csdn.net/detail/yanglw_ahut/4522913
      

  15.   

    如有需要请联系我,给你开个户 QQ704610198 还有可以获取网站访客QQ号的程序 程序源码也可出售。
      

  16.   

     如有需要请联系我,给你开个户 QQ704610198 还有可以获取 网站访客QQ号 的程序 程序源码也可出售