3G / 4G无法正常工作,但WIFI确实如此,Android工作室

时间:2016-02-22 20:56:30

标签: java android

我有一个应用程序,它使用Internet下载图片然后显示它。 当我使用WIFI时,一切都很完美。 当我使用我的蜂窝数据(4G或LTE)时,我有以下错误:

02-22 21:38:08.532  14183-14739/castiel.changes W/System.err﹕java.net.SocketTimeoutException
02-22 21:38:08.541  14183-14739/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
02-22 21:38:08.541  14183-14739/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
02-22 21:38:08.541  14183-14739/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
02-22 21:38:08.541  14183-14739/castiel.changes W/System.err﹕ at com.android.okio.Okio$2.read(Okio.java:113)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:147)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:94)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.readChunkSize(HttpConnection.java:514)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:495)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at java.io.InputStream.read(InputStream.java:162)
02-22 21:38:08.542  14183-14739/castiel.changes W/System.err﹕ at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:194)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:153)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:140)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at java.io.BufferedInputStream.read(BufferedInputStream.java:290)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at java.io.InputStream.read(InputStream.java:162)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:154)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:567)
02-22 21:38:08.543  14183-14739/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.getImageUrl(BlackMarket.java:97)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.downloadImage(BlackMarket.java:110)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.doInBackground(BlackMarket.java:83)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.doInBackground(BlackMarket.java:78)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-22 21:38:08.544  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-22 21:38:08.545  14183-14739/castiel.changes W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-22 21:38:08.545  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-22 21:38:08.545  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-22 21:38:08.545  14183-14739/castiel.changes W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
02-22 21:38:08.545  14183-14739/castiel.changes W/System.err﹕ java.net.MalformedURLException
02-22 21:38:08.548  14183-14739/castiel.changes W/System.err﹕ at java.net.URL.<init>(URL.java:152)
02-22 21:38:08.548  14183-14739/castiel.changes W/System.err﹕ at java.net.URL.<init>(URL.java:125)
02-22 21:38:08.548  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.downloadImage(BlackMarket.java:111)
02-22 21:38:08.548  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.doInBackground(BlackMarket.java:83)
02-22 21:38:08.549  14183-14739/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.doInBackground(BlackMarket.java:78)
02-22 21:38:08.549  14183-14739/castiel.changes W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-22 21:38:08.550  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-22 21:38:08.555  14183-14739/castiel.changes W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-22 21:38:08.555  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-22 21:38:08.555  14183-14739/castiel.changes W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-22 21:38:08.555  14183-14739/castiel.changes W/System.err﹕ at java.lang.Thread.run(Thread.java:818)
02-22 21:44:58.942  14183-14183/castiel.changes I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3d16c587 time:687507851
02-22 21:45:01.395  14183-14183/castiel.changes I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3eec504a time:687510304
02-22 21:45:02.337  14183-14183/castiel.changes I/Timeline﹕ Timeline: Activity_launch_request id:castiel.changes time:687511245
02-22 21:45:02.503  14183-14183/castiel.changes I/Timeline﹕ Timeline: Activity_idle id: android.os.BinderProxy@3c621602 time:687511412
02-22 21:45:05.787  14183-16350/castiel.changes W/System.err﹕ java.net.SocketTimeoutException
02-22 21:45:05.789  14183-16350/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488)
02-22 21:45:05.789  14183-16350/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
02-22 21:45:05.795  14183-16350/castiel.changes W/System.err﹕ at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
02-22 21:45:05.795  14183-16350/castiel.changes W/System.err﹕ at com.android.okio.Okio$2.read(Okio.java:113)
02-22 21:45:05.795  14183-16350/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:147)
02-22 21:45:05.796  14183-16350/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:94)
02-22 21:45:05.796  14183-16350/castiel.changes W/System.err﹕ at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.readChunkSize(HttpConnection.java:514)
02-22 21:45:05.798  14183-16350/castiel.changes W/System.err﹕ at com.android.okhttp.internal.http.HttpConnection$ChunkedSource.read(HttpConnection.java:495)
02-22 21:45:05.799  14183-16350/castiel.changes W/System.err﹕ at com.android.okio.RealBufferedSource$1.read(RealBufferedSource.java:168)
02-22 21:45:05.799  14183-16350/castiel.changes W/System.err﹕ at java.io.InputStream.read(InputStream.java:162)
02-22 21:45:05.799  14183-16350/castiel.changes W/System.err﹕ at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:194)
02-22 21:45:05.799  14183-16350/castiel.changes W/System.err﹕ at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:153)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:140)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at java.io.BufferedInputStream.read(BufferedInputStream.java:290)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at java.io.InputStream.read(InputStream.java:162)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:154)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:567)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:493)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:205)
02-22 21:45:05.802  14183-16350/castiel.changes W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:194)
02-22 21:45:05.803  14183-16350/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.getImageUrl(BlackMarket.java:97)
02-22 21:45:05.803  14183-16350/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.downloadImage(BlackMarket.java:110)
02-22 21:45:05.803  14183-16350/castiel.changes W/System.err﹕ at castiel.changes.BlackMarket$Download.doInBackground(BlackMarket.java:83)

和线条和线条再次划线哈哈。

这是我的代码:

public class BlackMarket extends ActionBarActivity {
ImageView BlackImage ;
TextView prez ;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_black_market);
        BlackImage = (ImageView) findViewById(R.id.imageBlack);
        prez = (TextView) findViewById(R.id.prez);
        new Download().execute();


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_black_market, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}


private class Download extends AsyncTask<String, Void, String> {
    private String updateDate = "Mise à jour du: ";
    private Bitmap bitmap = null ;
    @Override
    protected String doInBackground(String... params) {
        this.downloadImage();
        return null;
    }

    @Override
    protected void onPostExecute(String result){
        prez.setText("Les devises sont à l'unité et le prix de vente et d'achat sont en DA.\nExemple:\n euro = 182,5 DA à la vente.\n\n" + this.updateDate);
        BlackImage.setImageBitmap(this.bitmap);
    }

    public String getImageUrl(String url) {
        Document document;
        String imageUrl = null;
        try {
            document = Jsoup.connect(url).get();
            Elements img = document.select("img[src$= DevisesDZ%2BCurrency.png]");
            imageUrl = img.attr("src");
            this.updateDate += document.getElementsByTag("h3").get(1).getAllElements().get(1).toString().split(">", 10)[2].split("<")[0];
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return imageUrl;
    }

    public void downloadImage() {
        try {
            String imageUrl = getImageUrl("http://www.devisesdz.com");
            URL urlImage = new URL(imageUrl);
            HttpURLConnection connection = (HttpURLConnection) urlImage.openConnection();
            connection.setConnectTimeout(70000);
            InputStream inputStream = connection.getInputStream();
            this.bitmap = BitmapFactory.decodeStream(inputStream);

        }  catch (IOException e) {
            e.printStackTrace();
        }
    }


}

}

正如我所说,一切都与WIFI完美配合,但与蜂窝数据无关? 提前为你提供帮助:D

1 个答案:

答案 0 :(得分:0)

您希望在Manifest.xml中添加用户权限,以便在Android手机中启用GPRS / 3G / 4G网络