data/data/包名目录下的缓存文件。/sdcard/Android/data/包名下存储文件。



FileExplorerFragment页面,点击file文件itemFileExplorerFragment页面,否则跳转到文件详情页面FileExplorerFragment当作B,文件详情页面当作C,宿主Activity当作A。也就是说,点击返回键,依次关闭了fragment直到没有,回到宿主activity页面。再次点击返回键,则关闭activity!FileExplorerFragment列表页面(push一个fragment对象到队列中),关闭一个列表页面(remove最上面那个fragment对象,然后调用FragmentManager中popBackStack操作关闭fragment) /** * 回退fragment任务栈操作
* @param fragment fragment
*/
public void doBack(Fragment fragment) {
if (mFragments.contains(fragment)) {
mFragments.remove(fragment);
FragmentManager fm = getSupportFragmentManager();
//回退fragment操作
fm.popBackStack();
if (mFragments.isEmpty()) {
//如果fragment栈为空,则直接关闭宿主activity
finish();
}
}
}
```data/data/包名目录下的缓存文件。/sdcard/Android/data/包名下存储文件。/**
* 初始化默认文件。注意:加External和不加(默认)的比较
* 相同点:1.都可以做app缓存目录。2.app卸载后,两个目录下的数据都会被清空。
* 不同点:1.目录的路径不同。前者的目录存在外部SD卡上的。后者的目录存在app的内部存储上。
* 2.前者的路径在手机里可以直接看到。后者的路径需要root以后,用Root Explorer 文件管理器才能看到。
*
* @param context 上下文
* @return 列表
*/
private List<File> initDefaultRootFileInfos(Context context) {
List<File> fileInfos = new ArrayList<>();
//第一个是文件父路径
File parentFile = context.getFilesDir().getParentFile();
if (parentFile != null) {
fileInfos.add(parentFile);
}
//路径:/data/user/0/com.yc.lifehelper //第二个是缓存文件路径 File externalCacheDir = context.getExternalCacheDir(); if (externalCacheDir != null) { fileInfos.add(externalCacheDir); } //路径:/storage/emulated/0/Android/data/com.yc.lifehelper/cache //第三个是外部file路径 File externalFilesDir = context.getExternalFilesDir((String) null); if (externalFilesDir != null) { fileInfos.add(externalFilesDir); } //路径:/storage/emulated/0/Android/data/com.yc.lifehelper/files return fileInfos;}```}<!--既然是ContentProvider,那么需要像Activity一样在AndroidManifest.xml里声明:--><!--android:authorities 标识ContentProvider的唯一性,可以自己任意定义,最好是全局唯一的。--><!--android:name 是指之前定义的FileProvider 子类。--><!--android:exported="false" 限制其他应用获取Provider。--><!--android:grantUriPermissions="true" 授予其它应用访问Uri权限。--><!--meta-data 囊括了别名应用表。--><!--android:name 这个值是固定的,表示要解析file_path--><!--android:resource 自己定义实现的映射表--><provider android:name="com.yc.toolutils.file.ExplorerProvider" android:authorities="${applicationId}.fileExplorerProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_explorer_provider" /></provider>```
/** * 沙盒file工具配置脚本
*/
println('gradle file explorer , init start')
if (!isNeedUseExplorer()) {
println('gradle file explorer , not need file explorer')
return
}
println('gradle file isNeedUseExplorer = ture')dependencies { // 依赖 implementation('com.github.jacoco:runtime:0.0.23-SNAPSHOT')}//过滤,只在debug下使用def isNeedUseJacoco() { Map<String, String> map = System.getenv() if (map == null) { return false } //拿到编译后的 BUILD_TYPE 和 CONFIG。具体看 BuildConfig 生成类的代码 boolean hasBuildType = map.containsKey("BUILD_TYPE") boolean hasConfig = map.containsKey("CONFIG") println 'gradle file explorer isNeedUseExplorer hasBuildType =====>' + hasBuildType + ',hasConfig = ' + hasConfig String buildType = "debug" String config = "debug" if (hasBuildType) { buildType = map.get("BUILD_TYPE") } if (hasConfig) { config = map.get("CONFIG") } println 'gradle file explorer isNeedUseExplorer buildType =====>' + buildType + ',config = ' + config if (buildType.toLowerCase() == "debug" && config.toLowerCase() == "debug" && isNotUserFile()) { println('gradle file explorer debug used') return true } println('gradle file explorer not use') //如果是正式包,则不使用沙盒file工具 return false}static def isNotUserFile() { //在debug下默认沙盒file工具,如果你在debug下不想使用沙盒file工具,则设置成false return true}```原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。