gpt4 book ai didi

android - 如何从 .obb 文件中提取文件?

转载 作者:太空狗 更新时间:2023-10-29 14:08:00 29 4
gpt4 key购买 nike

在我的应用程序中,我在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com