做应用商店,下载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. hibernate建表 一对多 多的一方控制一的一方

    一对多 单向<one-to-many>通过calss操作student 外键在student表中,所以外键由student维护<many-to-one>通过student操作c ...

  2. RESTful HTTP的实践

    REST是一种风格,而不是标准.因为既没有REST RFC,也没有REST协议规范或者类似的规定.REST架构是Roy Fielding(他也是HTTP和URI规范的主要作者之一)在一篇论文中描述的. ...

  3. 又一枚神器:nginx

    一直听说过nginx的大名,也自己装过,但是未直接使用其各种牛X的功能. 今天试用了一下,只能用两字感叹:牛逼!比如它提供的配置检查功能,真是贴心极了,又比如我想要的静态内容浏览器端缓存功能,动态内容 ...

  4. 类 .xml

    pre{ line-height:1; color:#1e1e1e; background-color:#d2d2d2; font-size:16px;}.sysFunc{color:#627cf6; ...

  5. Prototype入门

    官网地址:http://prototypejs.org/ Prototype降低了客户端web编程的复杂性.为了解决现实存在的一些问题,Prototype对浏览器的脚本环境做了一些扩展,对原先笨拙的A ...

  6. linux常用的一些命令(不断增加中)

    linux 下重启 apache: httpd -k restart 下面这些大多命令都可以在<鸟哥私房菜>的服务器中的“常用网络指令”和基础中的“程序与资源管理”中找到ps -aux 这 ...

  7. 《学习OpenCV》练习题第四章第二题

    #include <highgui.h> #include <cv.h> #pragma comment (lib,"opencv_calib3d231d.lib&q ...

  8. 安装完 MySQL 后必须调整的 10 项配置(转)

    英文原文:10 MySQL settings to tune after installation 译文原文:安装完 MySQL 后必须调整的 10 项配置 当我们被人雇来监测MySQL性能时,人们希 ...

  9. C# Common Keyword

    [C# Common Keyword] 1.abstract Use the abstract modifier in a class declaration to indicate that a c ...

  10. 《Pandoc用户指南》之一

    @(编程) 1. 描述 Pandoc是一个用于从一种标记格式转换为另一种的Haskell库,还是一个使用该库的命令行工具.它可以读取markdown格式和Textile格式(的子集).reStruct ...