相关疑难解决方法(0)

如何在Java中为Android设置HttpResponse超时

我创建了以下用于检查连接状态的函数:

private void checkConnectionStatus() {
    HttpClient httpClient = new DefaultHttpClient();

    try {
      String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/"
                   + strSessionString + "/ConnectionStatus";
      Log.d("phobos", "performing get " + url);
      HttpGet method = new HttpGet(new URI(url));
      HttpResponse response = httpClient.execute(method);

      if (response != null) {
        String result = getResponse(response.getEntity());
        ...
Run Code Online (Sandbox Code Playgroud)

当我关闭服务器进行测试时,执行会等待很长时间

HttpResponse response = httpClient.execute(method);
Run Code Online (Sandbox Code Playgroud)

有谁知道如何设置超时以避免等待太久?

谢谢!

java android timeout httpresponse

332
推荐指数
5
解决办法
19万
查看次数

android为什么向服务器发送信息仅适用于WIFI?

我正在通过WIFI向服务器发送信息,一切都很好.现在我也想将信息发送到带有移动数据的服务器,我不知道为什么只适用于WIFI,移动数据流程异常无法连接到服务器.

这是移动数据失败的部分; 与WIFI完美结合:

int length=values.length();
    HttpParams httpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParams,9000);
    HttpConnectionParams.setSoTimeout(httpParams, 9000);

    HttpClient client = new DefaultHttpClient(httpParams);

    String url = saveData+"?Length="+length+"&Table="+temp;        
    HttpPost request = new HttpPost(url);
    request.setEntity(new ByteArrayEntity(values.toString().getBytes("UTF8")));        
    request.setHeader("json", values.toString());
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    // If the response does not enclose an entity, there is no need
    Log.d("test 7","test 7 last");
    if (entity != null) {
        InputStream instream = entity.getContent();
        String result =  RestClient.convertStreamToString(instream);
        Log.d("here",""+result);
        if(result.equals("success")&& ReadyOff==false){
            Ready=true;
        }else{
            Ready=false;
            ReadyOff=true;
        }
        Log.d("sent","valor de ready"+Ready); …
Run Code Online (Sandbox Code Playgroud)

networking android

3
推荐指数
1
解决办法
1109
查看次数

Android流m3u无线电在移动数据上失败(g3 /移动数据)

不太容易解释:

我有这个应用程序流媒体在线广播.问题首先是m3u格式(android在某种程度上通常不能像pls那样流),所以我必须用这个ParserM3UToURL解析url(我找到了某个地方)...像这样:

Uri u = Uri.parse(ParserM3UToURL.parse(STREAM_URL, sdkVersion, c));
player = MediaPlayer.create(c, u);
Run Code Online (Sandbox Code Playgroud)

大多数它工作正常,但它有一个错误......

我正在两个旧设备2.2.2上测试这个.(api等级17),其他4.3(api等级23).旧设备工作正常.它可以通过wifi或移动数据流式传输无线电,但较新的设备在移动数据流上存在一些问题(在wifi上工作正常).应用程序崩溃,因为解析函数返回null:http://pastebin.com/ghbAqGzM

而且我认为有更多的手机4.x而不是2.x android.这当然对我来说非常痛苦.不知怎的,我必须解决这个问题.所以我真的希望有人会对此有所了解.我希望我的解释不要混淆......

这是ParserM3UToURL.parse()函数:

public static String parse(String paramString, int sdkVersion, Context c)
{
    try
    {
      StrictModeWrapper.init(c);
      HttpURLConnection localHttpURLConnection = (HttpURLConnection)new URL(paramString).openConnection();
      InputStream localInputStream = localHttpURLConnection.getInputStream();
      BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localInputStream));
      StringBuffer localStringBuffer = new StringBuffer();
      while (true)
      {
        String str = localBufferedReader.readLine();
        if (str == null)
        {
          localHttpURLConnection.disconnect();
          localBufferedReader.close();
          localInputStream.close();
          break;
        }
        if (str.contains("http"))
        {
          localHttpURLConnection.disconnect();
          localBufferedReader.close();
          localInputStream.close();
          return str; …
Run Code Online (Sandbox Code Playgroud)

android media-player 3g

0
推荐指数
1
解决办法
1921
查看次数

标签 统计

android ×3

3g ×1

httpresponse ×1

java ×1

media-player ×1

networking ×1

timeout ×1