有一个老项目要上谷歌市场,开始了target30的踩坑路。
今天收到反馈,360清理大师能够拿到文件的根目录授权,也就是这个图
而我们做的目录授权,放到根目录是另一个图
wtf?这事什么鬼。别人行的我们不行,这不大好啊。
百度无果后,开始了反编译的模式。
1、下载最新的apk确认现象还在,
2、jadx-gui 查看反编译文件,找到对应的代码块
3、发现对方写的很复杂,·还用了反射搞事情,准备上debug
4、发现对面做了处理,不能回编译。pass
5、看一坨屎的代码
6、把反射搞定。最后的结果是获取了用户文件系统根目录的string。。。。
7、高高兴兴的把代码一致到代码中,run走你!
8、无效,想了良久,把对面AndroidManifest中的权限移植过来,run走你!
9、无效,想了良久,查看对面的target 发现是26
10、自身的target30改成26,run走你!
11、success,哇,终于能下结论啦。然并卵。。。。一看时间3个小时没了
12、总结:收获了获取用户文件系统根目录的方法。
public static String getStorageRootPath() {
String path = "/storage/emulated/0";
try {
android.os.storage.StorageManager storageManager = (StorageManager) CleanAppApplication.getInstance().getSystemService("storage");
Class clz = StorageManager.class;
Method getVolumeList = clz.getMethod("getVolumeList", null);
StorageVolume[] result = (StorageVolume[]) getVolumeList.invoke(storageManager, null);
for (StorageVolume o : result) {
String str = o.getDirectory().toString();//有api区分,getPath()方法是否直接存在
if (!TextUtils.isEmpty(str)) {
path = str;
}
}
} catch (Exception e) {
}
return path;
}



