Android路径相关

1 获取程序安装路径

1)android中获取当前程序路径
getApplicationContext().getFilesDir().getAbsolutePath()

2)android取已安装的程序列表
List<PackageInfo> packageInfoList =  getPackageManager().getInstalledPackages(0);

3)对安装路径的说明

http://developer.android.com/guide/appendix/install-location.html


Android应用程序的默认安装位置以及是否可移动取决于开发者在其AndroidManifest.xml中的设置:
 
<manifestxmlns:android="http://schemas.android.com/apk/res/android"        
      android:versionCode="1" 
      android:installLocation="auto" 
      android:versionName="1.0"> 
 
android:installLocation的值有三个 internalOnly ,auto,preferExternal,缺省值为internalOnly
internalOnly表示该应用程序只能安装到手机内部存储中。
auto表示由系统决定该应用程序安装到手机内部存储中还是SD卡中。 如果有SD卡且应用程序大于5M的话,安装到SD卡中,否则安排到手机内部存储中
preferExternal表示如果有SD卡就把该应用程序只能安装到SD卡中,否则安装到手机内部存储中。
 
android:installLocationinternalOnly时,用户在"Setting"->"Application"->"Manage applications"中不能把应用程序在SD卡与内存中相互移动 
android:installLocationautopreferExternal时,用户在"Setting"->"Application"->"Manage applications"中可以把应用程序在SD卡与内存中相互移动 
 
另外,adb shell 中可以使用 pm setInstallLocation 2 命令中强行更改安装位置。2代表的是强制安装在SD卡中,0代表自动,1代表强制装到手机内部存储中。
 
在代码中,对于高于Android 2.2的手机中,可以通过ApplicationInfo.FLAG_EXTERNAL_STORAGE 标记可以判断应用是否安装在Sdcard上,对于低于Android 2.2的手机可以通过ApplicationInfo的sourceDir属性为/sdcard/开头来确定APK安装的位置。
 
示例1
 
PackageManager pm=ctx.getPackageManager();
ApplicationInfo appInfo=pm.getApplicationInfo(pkgName,0);
if((appInfo.flags &ApplicationInfo.FLAG_EXTERNAL_STORAGE)!=0){
                // App on sdcard
                System.out.println(pkgName+" install on sdcard");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值