android getinputstream() 异常,Android中的失败inputStream.getInputStream()

我的应用程序检查是否有更新版本要使用。该过程在版本2中运行良好,但版本4.1不起作用。发生Android中的失败inputStream.getInputStream()

private class ExecuteUpdate implements Runnable {

@Override

public void run() {

try {

updateIntent = Updater.executeUpdate(updateHandler);

updateHandler.sendEmptyMessage(0);

} catch (IOException e) {

Message msg = new Message();

msg.obj = e;

updateHandler.sendMessage(msg);

}

}

}

public static Intent executeUpdate(Handler updateHandler) throws IOException {

URL url = new URL(Application.getInstance().getURL()

+ "/Prisma3Mobile/Prisma3Mobile.apk");

HttpURLConnection urlConnection = (HttpURLConnection) url

.openConnection();

urlConnection.setRequestMethod("GET");

urlConnection.setDoOutput(true);

urlConnection.connect();

File sdcard = Environment.getExternalStorageDirectory();

File file = new File(sdcard, "Prisma3Mobile.apk");

FileOutputStream fileOutput = new FileOutputStream(file);

InputStream inputStream = urlConnection.getInputStream();

byte[] buffer = new byte[1024];

int bufferLength = 0;

int contentLength = urlConnection.getContentLength();

// Determina valor máximo do ProgressDialog

Message msg = new Message();

msg.obj = contentLength;

updateHandler.sendMessage(msg);

while ((bufferLength = inputStream.read(buffer)) > 0) {

// Atualiza ProgressDialog

msg = new Message();

msg.obj = file.length();

updateHandler.sendMessage(msg);

fileOutput.write(buffer, 0, bufferLength);

}

fileOutput.close();

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setDataAndType(

Uri.fromFile(new File(Environment.getExternalStorageDirectory()

+ "/Prisma3Mobile.apk")),

"application/vnd.android.package-archive");

return intent;

}

以下问题:

07-23 08:04:24.625: W/System.err(14510): org.apache.http.conn.HttpHostConnectException: Connection to http://"192.168.1.30" refused

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:183)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:670)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:509)

07-23 08:04:24.655: W/System.err(14510): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)

07-23 08:04:24.655: W/System.err(14510): at com.sisteplantbrasil.util.Updater.checkForUpdates(Updater.java:74)

07-23 08:04:24.655: W/System.err(14510): at com.sisteplantbrasil.Main$Checkcnn.doInBackground(Main.java:133)

07-23 08:04:24.655: W/System.err(14510): at com.sisteplantbrasil.Main$Checkcnn.doInBackground(Main.java:1)

07-23 08:04:24.655: W/System.err(14510): at android.os.AsyncTask$2.call(AsyncTask.java:287)

07-23 08:04:24.655: W/System.err(14510): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)

07-23 08:04:24.660: W/System.err(14510): at java.util.concurrent.FutureTask.run(FutureTask.java:137)

07-23 08:04:24.665: W/System.err(14510): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)

07-23 08:04:24.665: W/System.err(14510): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)

07-23 08:04:24.665: W/System.err(14510): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)

07-23 08:04:24.665: W/System.err(14510): at java.lang.Thread.run(Thread.java:856)

07-23 08:04:24.665: W/System.err(14510): Caused by: java.net.ConnectException: failed to connect to /192.168.1.30 (port 80): connect failed: ENETUNREACH (Network is unreachable)

07-23 08:04:24.670: W/System.err(14510): at libcore.io.IoBridge.connect(IoBridge.java:114)

07-23 08:04:24.670: W/System.err(14510): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)

07-23 08:04:24.670: W/System.err(14510): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)

07-23 08:04:24.670: W/System.err(14510): at java.net.Socket.connect(Socket.java:842)

07-23 08:04:24.670: W/System.err(14510): at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)

07-23 08:04:24.670: W/System.err(14510): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)

07-23 08:04:24.670: W/System.err(14510): ... 16 more

07-23 08:04:24.670: W/System.err(14510): Caused by: libcore.io.ErrnoException: connect failed: ENETUNREACH (Network is unreachable)

07-23 08:04:24.675: W/System.err(14510): at libcore.io.Posix.connect(Native Method)

07-23 08:04:24.675: W/System.err(14510): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)

07-23 08:04:24.675: W/System.err(14510): at libcore.io.IoBridge.connectErrno(IoBridge.java:127)

07-23 08:04:24.675: W/System.err(14510): at libcore.io.IoBridge.connect(IoBridge.java:112)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值