- 浏览: 237098 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
江恂泽:
楼主 这家伙会把data 拆分开来 转换成day year形 ...
JsonUtil -
mdsp25xhm:
为何没有列表查询功能?
myBatis DAO封装
下载apk程序代码
protected File downLoadFile(String httpUrl) {
// TODO Auto-generated method stub
final String fileName = "updata.apk";
File tmpFile = new File("/sdcard/update");
if (!tmpFile.exists()) {
tmpFile.mkdir();
}
final File file = new File("/sdcard/update/" + fileName);
try {
URL url = new URL(httpUrl);
try {
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[256];
conn.connect();
double count = 0;
if (conn.getResponseCode() >= 400) {
Toast.makeText(Main.this, "连接超时", Toast.LENGTH_SHORT)
.show();
} else {
while (count <= 100) {
if (is != null) {
int numRead = is.read(buf);
if (numRead <= 0) {
break;
} else {
fos.write(buf, 0, numRead);
}
} else {
break;
}
}
}
conn.disconnect();
fos.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return file;
}
//打开APK程序代码
private void openFile(File file) {
// TODO Auto-generated method stub
Log.e("OpenFile", file.getName());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
}
安装:
String str = "/CanavaCancel.apk";
String fileName = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
卸载:
Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
Environment拥有一些可以获取环境变量的方法
package:com.demo.CanavaCancel 这个形式是 package:程序完整的路径 (包名+程序名).
protected File downLoadFile(String httpUrl) {
// TODO Auto-generated method stub
final String fileName = "updata.apk";
File tmpFile = new File("/sdcard/update");
if (!tmpFile.exists()) {
tmpFile.mkdir();
}
final File file = new File("/sdcard/update/" + fileName);
try {
URL url = new URL(httpUrl);
try {
HttpURLConnection conn = (HttpURLConnection) url
.openConnection();
InputStream is = conn.getInputStream();
FileOutputStream fos = new FileOutputStream(file);
byte[] buf = new byte[256];
conn.connect();
double count = 0;
if (conn.getResponseCode() >= 400) {
Toast.makeText(Main.this, "连接超时", Toast.LENGTH_SHORT)
.show();
} else {
while (count <= 100) {
if (is != null) {
int numRead = is.read(buf);
if (numRead <= 0) {
break;
} else {
fos.write(buf, 0, numRead);
}
} else {
break;
}
}
}
conn.disconnect();
fos.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return file;
}
//打开APK程序代码
private void openFile(File file) {
// TODO Auto-generated method stub
Log.e("OpenFile", file.getName());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
startActivity(intent);
}
安装:
String str = "/CanavaCancel.apk";
String fileName = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
卸载:
Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
startActivity(uninstallIntent);
Environment拥有一些可以获取环境变量的方法
package:com.demo.CanavaCancel 这个形式是 package:程序完整的路径 (包名+程序名).
发表评论
-
IMF简介-2
2013-07-09 17:56 845InputManager 由UI控件(View,TextVie ... -
IMF简介-1
2013-07-09 17:51 771Input Method Framework 目录 ... -
输入法 总结-3
2013-07-08 15:02 814public class MainActivity exten ... -
输入法 总结-4
2013-07-04 17:29 896public class InputActivity exte ... -
输入法 总结-3
2013-07-04 17:28 825public class InputApplication e ... -
输入法 总结-2
2013-07-04 17:23 731openwnn_pref_ja.xml <?xml v ... -
输入法 总结-2
2013-07-04 17:21 13openwnn_pref_ja.xml <?xml v ... -
输入法 总结-1
2013-07-04 17:19 762<application android ... -
Android快捷键
2013-03-15 14:39 762Home键(小房子键) 在 ... -
如何通过wifi调试android程序
2013-02-27 15:48 705android手机居然可以通过wifi进行程序的调试,太好了, ... -
Please ensure that adb is correctly located at 'D:\android-sdk-windows\platform-
2013-02-27 14:27 1597adt 出现ADB server didn't ACK, fa ... -
Android AsyncTask
2013-02-19 09:35 1051AsyncTask是抽象类,子类 ... -
Android ViewPager 左右滑动2-1
2013-01-29 10:12 1398public class PagerActivity exte ... -
Android ViewPager 左右滑动-3
2013-01-29 10:10 1054<?xml version="1.0" ... -
Android ViewPager 左右滑动-2
2013-01-29 10:10 1394/*** * 选中效果 */ pu ... -
Android ViewPager 左右滑动-1
2013-01-29 10:09 1326Store extends ActivityGroup imp ... -
Android SDCard操作-3
2013-01-26 18:31 840public static Intent getVid ... -
Android SDCard操作-2
2013-01-26 18:30 1023/** * 判断该应用在手机中的安装情况 ... -
Android SDCard操作-1
2013-01-26 18:27 987private static int INSTALLED = ... -
Android GridView显示图片
2013-01-05 22:52 6053package com.example.dynamicimag ...
相关推荐
DownLoadImageToGallery: Android 下载图片保存到相册
android 下载图片并缓存的demo
Android 下载图片 简单 例子 Android Image DownLoader
演示Android下载文件的例子,演示如何从网络下载文件。
android 下载图片到sdcard 并保存到指定的文件中
GADownloading有创意的Android 下载效果
android 下载网络 world 文件并打开
这是下载歌词的时候需要类,总共就三个,只需要使用一个接口方法就行了,返回List的对象
android下载网络pdf文件并展示。代码量非常小,直接粘贴复制需要的代码即可
一个android多线程下载小例子,附带源代码
这里有两个项目一个是下载的,一个是打开wrod文档的比较简单可以合成使用
其实不管是java还是android,都可以把输入输出流归为字节流和字符串流两种,一般的文字传输属于字符串流,而图片或者文件则属于字节流。这个demo是属于字节流
Android_SDK_2.1_下载与安装教程Android_SDK_2.1_下载与安装教程
这是最简单的下载网络文件的demo,希望对菜鸟有帮助,大神勿喷!
android 系统下的 下载并安装 apk 的源代码 整个项目打包
Android 下载中间件
android下载滚动条,供大家一起共同分享学习。
OkDownload 一个可靠,灵活,快速和强大的Android下载引擎
Android下载管理器,从Android6.0源码中分离出来可独立使用的下载管理器, 基本用法与官方API相同