android 内部存储 安装apk
来源:互联网 发布:雷神之锤linux版下载 编辑:程序博客网 时间:2024/06/03 22:28
在做应用自动更新模块下载apk时遇到了内部存储和sd卡存储两种情况,存在sk卡中存储apk可以正常安装,可是在内部存储中安装apk时出现了parse error的问题。
在网上搜了搜,大致分为两种方案:
1、在存储时给文件设定权限
2、在使用文件之前更改文件权限
起初思路并没有理清,就开始尝试,多次尝试之后问题仍没有解决,再请教了大牛之后才开始一点点分析。
首先使用普通的文件读写
File apkFile = new File(mSavePath, appName);FileOutputStream fos = new FileOutputStream(apkFile);
然后使用方案2:
String chmodCmd = "chmod 666 " + apkfile.getAbsolutePath();try { Runtime.getRuntime().exec(chmodCmd);} catch (Exception e) {}Intent i = new Intent(Intent.ACTION_VIEW); String filePath = "file://" + apkfile.toString();i.setDataAndType(Uri.fromFile(apkfile),"application/vnd.android.package-archive");mContext.startActivity(i);
问题解决了。
回过头来看方案一问什么不起作用,当我看文件时很吃惊,命名文件是下载下俩了,可是调用完了以后文件大小为0了,发现FileOutputStream fos = mContext.openFileOutput(appName,Context.MODE_WORLD_READABLE| Context.MODE_WORLD_WRITEABLE);在存文件和调用apk安装代码之前分别使用了一次,openFileOutput方法再次调用导致文件内容被清空,只需要在写文件的时候把文件权限置为读写权限便可。
String fileName = "tmp.apk";FileOutputStream fos = openFileOutput(fileName, MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);// write the .apk content here ... flush() and close()// Now start the standard instalation windowFile fileLocation = new File(context.getFilesDir(), fileName);Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(Uri.fromFile(fileLocation), "application/vnd.android.package-archive");context.startActivity(intent);
参考:
http://stackoverflow.com/questions/8784404/download-and-install-an-application-apk-from-internal-memory-no-sd-card
- android 内部存储 安装apk
- android 内部存储 更新apk
- 解决从内部存储设备安装apk提示Permission Denied
- android从内部存储写入、安装apk提示解析包错误,或者提示Permission Denied,文件不可用解决办法
- Android 7.0 app升级内部安装apk—FileProvider使用
- Android内部存储--InternalStorage
- Android 内部文件存储
- Android内部存储
- 调用android系统内部的安装apk应用界面进行安装应用程序,例如需要更新应用程序
- Android访问内部文件系统和模拟器中的SD卡,以及在模拟器安装apk文件
- apk 内部下载 完成后直接跳转系统安装界面 android
- Android 下载APK 安装APK 打开APK
- Android 下载APK 安装APK 打开APK
- Android 下载APK 安装APK 打开APK
- Android 下载APK 安装APK 打开APK
- Android如何编程设置APP安装位置(外部存储或内部存储)?
- (转)Android如何编程设置APP安装位置(外部存储或内部存储)?
- Android 内部存储常用知识
- 怎样写参数个数可变的宏
- [Android分享] 使用触摸手势(二)
- [图像增强]一. 图像增强了解
- 进程调度算法(进程调度策略)
- android中scrollview内部组件android:layout_height="fill_parent"无效的解决办法
- android 内部存储 安装apk
- flex 经典拖拽可编辑Tree
- Android 网络通信框架Volley简介(Google IO 2013)
- lack application"" /opt/toolchain_mips_nofpu/bin/lzma"", should install it问题解决办法
- Java transient关键字
- 程序员自我修养第一章基础知识总结
- java程序员修炼之道
- HttpHandler HttpModule入门篇
- JSP/SERVLET重定向技术综述