我在android上做了一个下载,下载不了,log提示是;01-07 09:10:21.363: INFO/AndroidRuntime(20915): NOTE: attach of thread 'Binder Thread #3' failed
       请问各位这是什么问题,怎么解决?
  
                         

解决方案 »

  1.   

    package com.iseeuon.android.update;import java.io.BufferedInputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;import android.app.Activity;
    import android.os.Environment;
    import android.os.Handler;
    import android.os.Message;
    import android.util.Log;
    import android.view.View;
    import android.widget.Toast;public class update extends Activity {
    public update() {
    download();
    } public void download() {
    File dir = null;
    File file = null; if (Environment.getExternalStorageState().equals(
    Environment.MEDIA_MOUNTED)) {
    Log.v("tag", "---------create file");
    // 获得sdcard目录
    dir = Environment.getExternalStorageDirectory();
    // 在指定目录新建文件
    file = new File(dir, "test.apk");
    }
    FileOutputStream fos = null;
    try {
    fos = new FileOutputStream(file);
    } catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    // 缓存
    byte[] bf = new byte[8192];
    int current = 0;
    try {
    // 创建一个URL对象
    URL url = new URL("http://192.168.200.233/test.apk");// spec:资源连接地址
    HttpURLConnection connect = (HttpURLConnection) url
    .openConnection();
    // 从服务端下载Http资源,设置读取权限
    connect.setDoInput(true);
    // //上传资源到服务端,设置写入权限
    // connect.setDoOutput(true);
    // 设置连接服务器超时时间
    connect.setConnectTimeout(5 * 1000);
    // 设置从服务器读取数据超时时间
    connect.setReadTimeout(30 * 1000);
    // 获得网络连接状态码
    int code = connect.getResponseCode();
    // 判断是否连接成功(HttpURLConnection.HTTP_OK==200,0-200都属正常)
    if (code == HttpURLConnection.HTTP_OK) {
    // //打开连接获取资源(不写也没关系,调用getInputStream()默认会打开连接
    // connect.connect();
    InputStream is = connect.getInputStream();
    BufferedInputStream bis = new BufferedInputStream(is);
    while ((current = bis.read(bf)) != -1) {
    fos.write(bf, 0, current);
    }
    bis.close();
    fos.close();
    // 断开连接
    connect.disconnect();
    } } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } final Handler handler = new Handler() {
    public void handleMessage(Message msg) {
    // 提示用户下载完成
    if (msg.what == 1) {
    Toast.makeText(update.this, "down succes",
    Toast.LENGTH_SHORT).show();
    } else {
    Toast.makeText(update.this, "down fail", Toast.LENGTH_SHORT)
    .show();
    }
    super.handleMessage(msg);
    } public void onClick(View v) {
    // 开启下载线程
    Thread thread = new Thread(new downThread());
    thread.start();
    }
    };
    }
    }class downThread implements Runnable { public void run() {
    // TODO Auto-generated method stub
    // 下载资源
    new update().download();
    Message msg = new Message();
    msg.what = 1;
    final Handler handler = new Handler();
    handler.sendMessage(msg);
    }
    }以上我写的一个用来从服务器上下载东西的程序,
    我运行程序时 logcat总是提示:
    01-07 09:28:16.555: INFO/AndroidRuntime(23276): NOTE: attach of thread 'Binder Thread #3' failed
      

  2.   

    看了一下你的代码,好像没什么问题,你在你的工程androidmanifest.xml文件看一下,是不是没有添加上网的权限啊?
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
      

  3.   

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setDataAndType(Uri.parse("file://" + filePath),
    "application/vnd.android.package-archive");
    getApplicationContext().startActivity(intent);
    自动安装的。
      

  4.   

    請問一下 01-07 09:28:16.555: INFO/AndroidRuntime(23276): NOTE: attach of thread 'Binder Thread #3' failed
    這個問題是怎麼解決的呢? 因為我也有遇到類似的問題,謝謝!
      

  5.   

    請問一下 01-07 09:28:16.555: INFO/AndroidRuntime(23276): NOTE: attach of thread 'Binder Thread #3' failed
    這個問題是怎麼解決的呢? 因為我也有遇到類似的問題,謝謝!