您的位置:首页 > 移动开发 > Android开发

安卓获取路径

2016-06-13 10:24 489 查看
1.获取当前程序路径

getApplicationContext().getFilesDir().getAbsolutePath();

2.获取程序的安装包路径

String path=getApplicationContext().getPackageResourcePath();

3.获取程序数据库的位置

getApplicationContext().getDatabasePath(s).getAbsolutePath();

4.获取安卓内置的内存的路径

String path=Environment.getExternalStorageDirectory().getAbsolutePath();
安卓获取下载的目录,我的写法:
String sdCardPath1 = "";
if (FileUtil.getSdCardDirectory() == null) {
sdCardPath1 = mContext.getFilesDir().getAbsolutePath();
} else {
sdCardPath1 = FileUtil.getSdCardDirectory() + File.separator+ Constant.PLUGIN_PATH;
File tmpFile = new File(sdCardPath1);
if (!tmpFile.exists()) {
tmpFile.mkdir();
}
}
final String sdCardPath = sdCardPath1;
<pre class="java" name="code">public static String getSdCardDirectory() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
File sdcardDir = Environment.getExternalStorageDirectory();
return sdcardDir.getAbsolutePath();
} else {
return null;
}
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android 存储