0

我正在开发一个具有下载选项的应用程序

OnState 中的本地服务器:-

从我的 Android 模拟器,我下载音频文件并将其保存在 Distination Path(本地服务器)中,然后我播放了音频文件,它工作正常,然后我的问题

OffState 中的本地服务器:-

下载本地服务器时,(192.168.0.2/android/a1.mp3(本地服务器路径))但是它是OffState,它仍然显示加载图标..如何找到处于OffState或Onstate的服务器。是否有任何连接失败的委托函数并出现错误

4

1 回答 1

0

你在这里需要的是setTimeout。

下面的代码剪辑器将为您提供帮助。

HttpPost httpPost = new HttpPost(url);
    StringEntity se = new StringEntity(envelope,HTTP.UTF_8);
    httpPost.setEntity(se);

    HttpParams httpParameters = new BasicHttpParams();
    // Set the timeout in milliseconds until a connection is established.
    int timeoutConnection = 3000;
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    // Set the default socket timeout (SO_TIMEOUT) 
    // in milliseconds which is the timeout for waiting for data.
    int timeoutSocket = 3000;
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

    DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
    BasicHttpResponse httpResponse = (BasicHttpResponse)  httpClient.execute(httpPost);

    HttpEntity entity = httpResponse.getEntity();
    return entity;

如果您在特定时限内没有得到回复,请在此处。代码会抛出ConnectTimeoutException.

于 2012-06-02T10:52:23.223 回答