为什么app无法从服务器获取http响应?它适用于妻子,但不适用于3G?

时间:2013-01-28 10:33:09

标签: android android-widget http-post http-proxy

我正在尝试编写一个应用程序,该应用程序发布传入的电话号码并获得响应,并通过使用Toast到屏幕显示结果。它适用于模拟器和手机中的妻子,但不适用于3G。通话结束后,toast显示结果。我已经将APN更改为互联网,但它不起作用。有没有办法用3G做到这一点?

广播接收器

if(TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {

            incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER); 

            if   (!client.contactExists(context, incomingNumber)){

            try {

             String response=client.login5(incomingNumber,hash);
            JSONObject jObject = new JSONObject(response);
        resusername = jObject.getString("name");
         reshash = jObject.getString("hash");



         Toast a=  Toast.makeText(context,"\n"+"Telefon Numarası:" + incomingNumber+"\n"+"Adına Kayıtlı Kişi:" +  resusername+"\n", Toast.LENGTH_LONG);
         a.setGravity(Gravity.TOP|Gravity.CENTER, 0, 0);
         a.show();



        //   msg += "My phone number:" +  client.getMy10DigitPhoneNumber()+"\n";            

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
      /*  if(reshash==hash && frame.konrolnum(incomingNumber)!=true) {
        msg+="User name is: "+resusername;
        frame.createContact(resusername, incomingNumber);}*/


        } }

HttpClient的

public String login5(String tlf,String hash) {      
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy); 

    InputStream is = null;
     String result = "";
     ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

     try 
     { 


           HttpClient httpclient = new DefaultHttpClient();
           HttpProtocolParams.setUseExpectContinue(httpclient.getParams(), false);
           HttpPost httppost = new HttpPost("http://www.whois118.com/broadcast.php");
           nameValuePairs.add(new BasicNameValuePair("telefon",tlf));
           nameValuePairs.add(new BasicNameValuePair("hash", hash));
           httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
           HttpResponse response = httpclient.execute(httppost);
           HttpEntity entity = response.getEntity();

           is = entity.getContent();

      }

      catch (Exception e)
      {
       Log.e("log_tag", "Error in http connection " + e.toString());
      }
  // convert response to string
      try 
      {
           BufferedReader reader = new BufferedReader(new InputStreamReader( is, "UTF-8"), 8);
           StringBuilder sb = new StringBuilder();
           String line = null;

       while ((line = reader.readLine()) != null) 
       {
           sb.append(line + "\n");
       }

        is.close();
        result = sb.toString();



       Log.v("log","Result :"+result);
  } 
  catch (Exception e)
  {
   Log.v("log", "Error converting result " + e.toString());
  }
    return result;
}

0 个答案:

没有答案