作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在我的应用程序中,我在 Android->obb->packagename->main.1.packagename.obb 下载了扩展文件。有人可以向我解释,即使有示例代码如何从中提取我的文件吗?
我尝试将 APK 扩展 Zip 库用作:
ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(MainActivity.this, 3, 0);
for (ZipResourceFile.ZipEntryRO entry : expansionFile.getAllEntries())
Log.d("",entry.mFileName);
InputStream input = expansionFile.getInputStream(Environment.getExternalStorageDirectory().toString()
+ "/sdcard/Android/obb/com.example.project/main.3.com.example.project.obb/obb/file.zip/file.apk");
但是 expansionFile 总是空的。.obb 文件是使用 Jobb 创建的,用于文件夹 obb/file.zip。
最佳答案
通过以下代码解决:
final StorageManager storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
String obbPath = Environment.getExternalStorageDirectory() + "/Android/obb";
final String obbFilePath = obbPath + "/com.example.project/main.3.com.example.project.obb";
OnObbStateChangeListener mount_listener = new OnObbStateChangeListener() {
public void onObbStateChange(String path, int state) {
if (state == OnObbStateChangeListener.MOUNTED) {
if (storageManager.isObbMounted(obbFilePath)) {
Log.d("Main","Mounted successful");
String newPath = storageManager.getMountedObbPath(obbFilePath);
File expPath = new File(newPath+"/file.zip/file.apk");
Log.d("Main","File exist: " + expPath.exists());
}
}
}
};
storageManager.mountObb(obbFilePath, "key", mount_listener);
挂载 .obb 文件后,我可以在路径 mnt/obb/myfolder 中访问我的数据。
关于android - 如何从 .obb 文件中提取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31394288/
我是一名优秀的程序员,十分优秀!