android 自动更新的时候出现解析程序包时出现问题,签名是一样的,apk也下载成功是完整的,但是有的手机自动安装的时候就会报解析程序包时出现问题,有的手机却能自动安装成功。在下载目录里面手动安装就能安装成功。。何解 问题解决再送100分代码如下:
new Thread() {
public void run() {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
try {
response = client.execute(get);
HttpEntity entity = response.getEntity();
int length = (int) entity.getContentLength(); // 获取文件大小
pBar.setMax(length); // 设置进度条的总长度
InputStream is = entity.getContent();
if (is != null) {
File file = new File(
Environment.getExternalStorageDirectory(),
"Health Manager.apk");
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[32];
int ch = -1;
int process = 0;
while ((ch = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, ch);
process += ch;
pBar.setProgress(process); //实时更新进度了!
}
}
fileOutputStream.flush();
is.close();
if (fileOutputStream != null) {
fileOutputStream.close();
}
down();
} catch (Exception e) {
e.printStackTrace(); try {
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
myHandler.sendEmptyMessage(5);
}
}.start();void down() {
myHandler.post(new Runnable() {
public void run() {
pBar.cancel();
update();
}
});
} // 安装文件,一般固定写法
void update() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "Health Manager.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
}
new Thread() {
public void run() {
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
try {
response = client.execute(get);
HttpEntity entity = response.getEntity();
int length = (int) entity.getContentLength(); // 获取文件大小
pBar.setMax(length); // 设置进度条的总长度
InputStream is = entity.getContent();
if (is != null) {
File file = new File(
Environment.getExternalStorageDirectory(),
"Health Manager.apk");
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[32];
int ch = -1;
int process = 0;
while ((ch = is.read(buf)) != -1) {
fileOutputStream.write(buf, 0, ch);
process += ch;
pBar.setProgress(process); //实时更新进度了!
}
}
fileOutputStream.flush();
is.close();
if (fileOutputStream != null) {
fileOutputStream.close();
}
down();
} catch (Exception e) {
e.printStackTrace(); try {
if (fileOutputStream != null) {
fileOutputStream.close();
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
myHandler.sendEmptyMessage(5);
}
}.start();void down() {
myHandler.post(new Runnable() {
public void run() {
pBar.cancel();
update();
}
});
} // 安装文件,一般固定写法
void update() {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(new File(Environment
.getExternalStorageDirectory(), "Health Manager.apk")),
"application/vnd.android.package-archive");
startActivity(intent);
}
解决方案 »
- 求助:android下如何调用邮件系统
- android 文件浏览按钮
- SQLite小小疑问
- 关于graphical layout 效果显示不出来的问题。,求解。!!!
- 各位大虾,我的eclipse会自动关闭啊。。为什么?
- 求GoogleAndroidSDK开发范例大全源码 pdf 和 OPhone应用开发权威指南 pdf 下载
- android可以通过WIFI直接与另一个手机通信吗?
- 请问多层Fragment重叠,如何让底层的Fragment不响应点击等事件?
- 求大神求解脱 来看看我的代码
- 关于window Qt Android 编译
- android中的异常
- 实现出厂设置 如何跳过 设备管理器激活 这一步
你看下这个帖子,好像是没有执行权限
http://bbs.csdn.net/topics/380117090
在模拟器上是吧,
adb push HealthManager.apk /data/local/tmp/
chmod 777 /data/local/tmp
chmod 777 /data/local/tmp/HealthManager.apk然后把代码里的 HealthManager.apk 改为 /data/local/tmp/HealthManager.apk , 再试下看吧
adb devices
若手机连接ok, 这个命令执行后,在命令行下会输出设备。
adb push d:\\test.apk /data/local/tmp/
adb shell 进入到手机命令行
chmod 777 /data/local/tmp/test.apk如果觉得上面有困难,就这样:
在代码里,将apk放到context.getFilesDir().getAbsolutePath()下,并赋于可执行权限。
代码里用到文件时,也用context.getFilesDir().getAbsolutePath() + “/" + "test.apk"