安卓获取路径

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