做应用商店,下载apk,考虑一种情况,如果没有sd卡的情况下就将apk下载到 Internal Cache目录下。

下载都正常,但是在安装的时候提示Permission Denied

/data/data/mypackage/apps/app.apk': Permission denied 

好像是因为data目录下的文件只有r+w权限,没有x(执行)权限,MODE_PRIVATE。

FileOutputStream fos = openFileOutput("app.apk", Context.MODE_PRIVATE);

有一种解决方案是,在下载apk创建输出流的时候指定读写权限:

[java] view plaincopy

String fileName = "tmp.apk";  

FileOutputStream fos = openFileOutput(fileName,MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);  

File 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);

此方案可行,但是我所做的下载使用的断点续传,RandomAccessFile.在构造方法中没办法像openFileOutput(fileName,MODE_WORLD_READABLE | MODE_WORLD_WRITEABLE);一样指定读写权限。所以弃之。

然后在stackoverflow上找到了另外的方案,手动授权:

try {
String[] args2 = { "chmod", "604", apkpath};
Runtime.getRuntime().exec(args2);
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" +apkpath), "application/vnd.android.package-archive");
mContext.startActivity(intent);

解决从内部存储设备安装apk提示Permission Denied的更多相关文章

  1. 服务器ssh登录提示“Permission denied, please try

    原因:不用怀疑,一般情况下,就是你密码输入错误了. 解决:找到正确的密码输入. 当然,也有可能是下面的情况: 在Windows中使用ssh客户端连接,提示"ssh服务器拒绝了密码,请再试一次 ...

  2. Ldap用户登陆操作系统提示Permission denied, please try again.

    昨天一个同事he告诉我他的ldap账户无法登录系统,提示Permission denied, please try again 解决方法: 先在百度上找了下别人的博客参考了下 https://blog ...

  3. /tmp目录下执行脚本失败提示Permission denied

    Linux上执行Shell脚本运行失败提示Permission denied一个问题,挺好的问题,切中了知识盲点. 问题现象 Shell脚本在/tmp目录下,执行./test.sh运行失败,提示Per ...

  4. [转帖]Linux /tmp目录下执行脚本失败提示Permission denied

    Linux /tmp目录下执行脚本失败提示Permission denied https://www.cnblogs.com/linyfeng/p/11087655.html 国产化的环境上 就有一个 ...

  5. linux 下执行.sh文件总是提示permission denied

      linux 下执行.sh文件总是提示permission denied 如果你是root登陆的话(不是的话,切换到root用户,对*.sh赋可执行的权限) chmod 777 *.sh or ch ...

  6. linux 下执行.sh文件提示permission denied

    linux 下执行.sh文件提示permission denied 在脚本文件目录下运行命令,赋予权限: chmod 777 *.sh or chmod +x  *.sh

  7. Mac环境配置好ant后提示Permission denied

    1.ant环境变量配置如下 打开终端,输入vi ~/.bash_profile export ANT_HOME=/Users/administrator/Documents/software/apac ...

  8. 【IOS】mac终端运行.sh文件总是提示permission denied

    如果我目录jni有一个list.sh文件 我直接 nxgametekiMacBook-Air:jni luonan$  ./list.sh ../../Classes 提示 permission de ...

  9. android 内部存储 安装apk

    在做应用自动更新模块下载apk时遇到了内部存储和sd卡存储两种情况,存在sk卡中存储apk可以正常安装,可是在内部存储中安装apk时出现了parse error的问题. 在网上搜了搜,大致分为两种方案 ...

随机推荐

  1. sqlplus常用命令

    原文 sqlplus常用命令 desc 表名            显示表的结构 show user           显示当前连接用户 show error            显示错误 sho ...

  2. 已经被cocos2dx给折腾的想要放弃它,专注Unity3D的怀抱了!

    一直使用cocos2dx编写自己的2D小游戏,不得不说,编写个人的超级小规模的游戏,使用cocos2dx有一定的优势,首先门槛很低,编写2D游戏用起来也算顺手,可惜一直没有一个优秀的UI编辑器,好不容 ...

  3. GitHub使用教程及常见错误解决

    1.下载Git并安装 Git for Windows Git-1.8.4-preview20130916.exe 按照默认步骤完成安装 2.设置SSH建立计算机与Github的链接 2.1 点击 开始 ...

  4. 安卓 开发 The connection to adb is down, and a severe error has occured.

    The connection to adb is down, and a severe error has occured.问题解决 其原因就是其他进程占用了  ADB的端口,所以无法启动 遇到问题描 ...

  5. jQuery对select标签的常用操作

    1.获取当前选中项的value. $("#selector").val(); 2.获取当前选中项的text. $("#selector").find(" ...

  6. 将Tomcat注册为Windows服务

    1.从官网http://tomcat.apache.org/下载Tomcat. 2.将Tomcat压缩文件解压到相应的路径下(例如E:\TomcatServer) 3.从bin目录下找到service ...

  7. Package inputenc Error: Unicode char \u8: not set up for use with LaTeX.

    用TexStudio编辑文档时,不知是多加了空格还是啥,总是提示如下错误: Package inputenc Error: Unicode char \u8: not set up for use w ...

  8. Python 统计文本中单词的个数

    1.读文件,通过正则匹配 def statisticWord(): line_number = 0 words_dict = {} with open (r'D:\test\test.txt',enc ...

  9. Struts Convention Plugin 流程 (2.1.6+)

    首先添加lib: <dependency> <groupId>org.apache.struts</groupId> <artifactId>strut ...

  10. 面试题收集——Java基础部分(一)

    原博文出自于: http://www.cnblogs.com/xdp-gacl/p/3641769.html 感谢! 1.一个".java"源文件中是否可以包括多个类(不是内部类) ...