0

我一直在尝试将我的应用程序转换为使用 APK 扩展文件,由于某种原因,下面的代码找不到我的 APK 扩展文件的路径...

static String[] getAPKExpansionFiles(Context ctx, int mainVersion, int patchVersion) {
    Log.v(TAG, "Utils.getAPKExpansionFiles [27] mainVersion is " + mainVersion + " patchVersion = " + patchVersion );
    String packageName = ctx.getPackageName();
    Log.v(TAG, "Utils.getAPKExpansionFiles [27] packageName is [" + packageName + "]" );
    Vector<String> ret = new Vector<String>();
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        Log.v(TAG, "Utils.getAPKExpansionFiles [32] MEDIA_MOUNTED" );
        // Build the full path to the app's expansion files
        File root = Environment.getExternalStorageDirectory();
        Log.v(TAG, "Utils.getAPKExpansionFiles [35] root = " + root);
        File expPath = new File(root.toString() + EXP_PATH + packageName);
        Log.v(TAG, "Utils.getAPKExpansionFiles [37] expPath " + expPath );

        // Check that expansion file path exists
        if (expPath.exists()) {
                ...
        } else {
            Log.v(TAG, "Utils.getAPKExpansionFiles [60] expPath DOES NOT EXISTS" );
        }
    } else {
        Log.v(TAG, "Utils.getAPKExpansionFiles [57] NOT MEDIA_MOUNTED" );
    }
    String[] retArray = new String[ret.size()];
    ret.toArray(retArray);
    return retArray;
}

... logcat 显示了这个 ...

03-20 21:04:24.206: V/GospelofMatthewAudiobook(10965): Utils.getAPKExpansionFiles [37] expPath /mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook
03-20 21:04:24.214: V/GospelofMatthewAudiobook(10965): Utils.getAPKExpansionFiles [60] expPath DOES NOT EXISTS

...即使路径确实存在并且文件在那里,如此屏幕截图所示:

在此处输入图像描述 我很确定我没有错字并且路径存在。那么为什么会expPath.exists()返回false。

感谢 Ted 的回答......但我仍然在 logcat 中得到这个......

03-20 21:59:48.198: V/GospelofMatthewAudiobook(11988): Utils.getAPKExpansionFiles [37] expPath /mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook/main.1.com.redcricket.GospelofMatthewAudiobook.obb
03-20 21:59:48.198: V/GospelofMatthewAudiobook(11988): Utils.getAPKExpansionFiles [60] expPath DOES NOT EXISTS

...可能是我用 Windows 而不是avd. adb创建目录并将APK扩展zip文件推送到我的手机上的命令是什么?

4

1 回答 1

1

您需要命名文件本身。而不是这个:

File expPath = new File(root.toString() + EXP_PATH + packageName);

用这个:

File expPathDir = new File(root.toString() + EXP_PATH + packageName);
File expPath = new File(expPathDir,
    String.format("main.%d.%s.obb", mainVersion, packageName));

这将适用于主扩展包。您应该有类似的方法来访问使用该格式的补丁String.format("patch.%d.%s.obb", patchVersion, packageName)

文件的完整路径应该类似于

/mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook/main.123./mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook.obb
于 2013-03-21T04:53:12.463 回答