对APK进行覆盖安装和卸载
来源:互联网 发布:淘宝怎样买东西便宜 编辑:程序博客网 时间:2024/05/16 11:50
public class PackageManager {
private Context mContext;
private String apkName = "";
public PackageManager(Context mContext, String apkName) {
// TODO Auto-generated constructor stub
this.mContext = mContext;
this.apkName = apkName;
}
* 如xxx.apk
*/
public void installApk(/*InputStream is*/) {
String apkPathName =Environment.getExternalStorageDirectory()+ "/kuaixindai/"+ apkName;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String type = "application/vnd.android.package-archive";
try {
// //不知道什么原因,当apk大于5M的时候就读取异常
File f = new File(apkPathName);
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = mContext.openFileOutput(apkName,
Context.MODE_PRIVATE + Context.MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
fis.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
File f = new File(apkPathName);
if (f.exists()) {
intent.setDataAndType(Uri.fromFile(f), type);
mContext.startActivity(intent);
}
}
//卸载
public void uninstallApk(String packageName) {
Uri packageURI = Uri.parse("package:" + packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
mContext.startActivity(uninstallIntent);
}
private Context mContext;
private String apkName = "";
public PackageManager(Context mContext, String apkName) {
// TODO Auto-generated constructor stub
this.mContext = mContext;
this.apkName = apkName;
}
/**安装
* @param apkName* 如xxx.apk
*/
public void installApk(/*InputStream is*/) {
String apkPathName =Environment.getExternalStorageDirectory()+ "/kuaixindai/"+ apkName;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
String type = "application/vnd.android.package-archive";
try {
// //不知道什么原因,当apk大于5M的时候就读取异常
File f = new File(apkPathName);
FileInputStream fis = new FileInputStream(f);
FileOutputStream fos = mContext.openFileOutput(apkName,
Context.MODE_PRIVATE + Context.MODE_WORLD_READABLE);
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.flush();
fis.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
File f = new File(apkPathName);
if (f.exists()) {
intent.setDataAndType(Uri.fromFile(f), type);
mContext.startActivity(intent);
}
}
//卸载
public void uninstallApk(String packageName) {
Uri packageURI = Uri.parse("package:" + packageName);
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);
mContext.startActivity(uninstallIntent);
}
0 0
- 对APK进行覆盖安装和卸载
- apk安装和卸载
- Android对APK文件的安装和卸载
- 模拟器安装和卸载APK
- apk的安装和卸载
- apk的安装和卸载
- android 安装和卸载apk
- Android模拟器上安装和卸载APK
- android 模拟器上安装和卸载apk
- android代码安装和卸载apk
- 如何用模拟器安装和卸载APK.
- 模拟器上安装和卸载apk
- 安装和卸载apk文件的方法
- android apk静默安装和卸载
- Android实现安装和卸载APK
- 如何用模拟器安装和卸载APK.
- android apk静默安装和卸载
- 安装和卸载指定apk的批处理文件
- 【转】PHP读取服务器端文件提供弹出下载窗口
- NOVA-SCHEDULER服务启动流程
- jdk配置环境变量
- Java List或Map对象和json字符串数据的相互转化
- monit 管理进程
- 对APK进行覆盖安装和卸载
- hibernate generator class="" id生成机制
- JAVA注释规范
- 对于这件事我本来是持
- Android数据的四种存储方式
- maven项目添加jar包.
- POJ 3667 Hotel
- chrome、Firefox调试技巧
- js实现动态消息提示框(模仿android系统中toast的效果)