Android 5.0.2三星Tab a上的HTTP请求速度极慢
我有一个应用程序,它在不同的线程中使用Android 5.0.2三星Tab a上的HTTP请求速度极慢,android,android-5.0-lollipop,httpurlconnection,Android,Android 5.0 Lollipop,Httpurlconnection,我有一个应用程序,它在不同的线程中使用HttpURLConnection进行大量下载。第一个活动在onCreate期间发出两个线程化请求。所有这些都可以在一些设备上正常工作,但现在我的客户(!)购买了一款三星Tab a SM-T550,搭载安卓5.0.2。 在这款平板电脑上,我的应用程序每次请求都需要几分钟,而其他设备只需要一秒钟。客户告诉我,在请求到达服务器之前,时间是浪费的。(基于日志文件中的时间戳) 其他应用程序运行良好,因此我的客户将此问题归咎于我 此设备或Android版本是否存在任何
HttpURLConnection
进行大量下载。第一个活动在onCreate
期间发出两个线程化请求。所有这些都可以在一些设备上正常工作,但现在我的客户(!)购买了一款三星Tab a SM-T550,搭载安卓5.0.2。
在这款平板电脑上,我的应用程序每次请求都需要几分钟,而其他设备只需要一秒钟。客户告诉我,在请求到达服务器之前,时间是浪费的。(基于日志文件中的时间戳)
其他应用程序运行良好,因此我的客户将此问题归咎于我
此设备或Android版本是否存在任何已知问题
更新:
今天我从我的客户那里拿到了平板电脑,将它连接到我的WLAN,它工作得很好!
但在他的办公室里,我可以自己看到,连接速度非常慢,而其他应用程序运行得很快。
这怎么可能?
客户拥有非常快速的DSL连接。(50或100兆比特-他不确定)
看起来,问题似乎是局部的,但我不知道在哪里寻找解决方案
这是我的密码:
public boolean requestHTTPData(TransferResult txResult, String url) {
boolean res = false;
this.txResult = txResult;
try {
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
txResult.setData(in);
txResult.setResult(TransferResult.RESULT_OK);
res = true;
}
catch (Exception e) {
txResult.setError(e.getLocalizedMessage());
}
return res;
}
以下是TranferResult的代码:
public class TransferResult {
public static final int RESULT_OK = 1;
public static final int RESULT_ERROR = -1;
public static final int RESULT_UNDEF = 0;
protected String response = null;
protected int result = RESULT_UNDEF;
protected StringBuffer errorText = null;
protected BufferedReader data = null;
protected Boot[] boote;
protected int startIndex = 0;
protected int anzahl = 0;
public String getResponse() {
return response;
}
public void setResponse(String response) {
this.response = response;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public BufferedReader getData() {
return data;
}
public void setData(BufferedReader data) {
this.data = data;
}
public boolean wasSuccessfull() {
return (result == RESULT_OK);
}
public Boot[] getBoote() {
return boote;
}
public void setBoote(Boot[] boote) {
this.boote = boote;
}
public int getStartIndex() {
return startIndex;
}
public void setStartIndex(int startIndex) {
this.startIndex = startIndex;
}
public int getAnzahl() {
return anzahl;
}
public void setAnzahl(int anzahl) {
this.anzahl = anzahl;
}
public void setError(String newErrorText) {
if (newErrorText != null && newErrorText.length() > 0) {
if (errorText == null) {
errorText = new StringBuffer();
} else {
errorText.append("\n");
}
this.errorText.append(errorText);
}
result = RESULT_ERROR;
}
public StringBuffer getErrorText() {
return errorText;
}
public void showError(Context context) {
if (errorText == null) {
setError("Errortext is NULL");
}
AlertDialog alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("");
alertDialog.setMessage(errorText);
alertDialog.show();
}
public TransferResult(Boot[] boote, int startIndex, int anzahl) {
super ();
this.setBoote(boote);
this.setStartIndex(startIndex);
this.setAnzahl(anzahl);
}
public TransferResult() {
this (null, 0, 0);
}
}
欢迎提出任何想法。'txResult.setData(in);'我们看不出您是否在那里摆弄。“txResult.setResult(TransferResult.RESULT_OK);”。你在告诉自己一切都好。即使出现问题。@greenapps:txResult.setData只存储数据供以后使用。@greenapps:如果出现问题,我希望出现异常并调用txResult.setError,其中setResult设置为RESULT_ERROR。这是不正确的。'txResult.setData(in);'我们看不出您是否在那里摆弄。“txResult.setResult(TransferResult.RESULT_OK);”。你在告诉自己一切都好。即使出了问题。@greenapps:txResult.setData只存储数据供以后使用。@greenapps:如果出了问题,我希望出现异常并调用txResult.setError,其中setResult设置为RESULT\u ERROR。这是不正确的。