APK扩展文件expPath不存在 [英] APK expansion file expPath does not exists

查看:191
本文介绍了APK扩展文件expPath不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图将我的应用程序使用APK扩展文件,由于某种原因,这个code以下无法找到的路径,我的APK扩展文件...

 静态的String [] getAPKExpansionFiles(上下文CTX,诠释mainVersion,诠释patchVersion){
    Log.v(TAG,Utils.getAPKExpansionFiles [27] ​​mainVersion是+ mainVersion +patchVersion =+ patchVersion);
    串的packageName = ctx.getPackageName();
    Log.v(TAG,Utils.getAPKExpansionFiles [27]的packageName是[+的packageName +]);
    矢量<串GT; RET =新矢量<串GT;();
    如果(Environment.getExternalStorageState()。等于(Environment.MEDIA_MOUNTED)){
        Log.v(TAG,Utils.getAPKExpansionFiles [32] MEDIA_MOUNTED);
        //构建完整路径应用程序的扩展文件
        文件根= Environment.getExternalStorageDirectory();
        Log.v(TAG,Utils.getAPKExpansionFiles [35]根=+根);
        文件expPath =新的文件(root.toString()+ EXP_PATH +的packageName);
        Log.v(TAG,Utils.getAPKExpansionFiles [37] expPath+ expPath);

        //检查扩展文件路径存在
        如果(expPath.exists()){
                ...
        } 其他 {
            Log.v(TAG,Utils.getAPKExpansionFiles [60] expPath不存在);
        }
    } 其他 {
        Log.v(TAG,Utils.getAPKExpansionFiles [57]不MEDIA_MOUNTED);
    }
    的String [] retArray =新的String [ret.size()];
    ret.toArray(retArray);
    返回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
 

...即使路径确实存在,并且该文件是有这表现在这个屏幕截图:

我是pretty的肯定我没有一个错字和路径存在。那么,为什么 expPath.exists()返回false。

感谢您的回答泰德......但我仍然得到这个在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 。你会在亚洲开发银行命令来创建显示目录和推到我的手机的APK扩展zip文件?

解决方案

您需要命名文件本身。取而代之的是:

 文件expPath =新的文件(root.toString()+ EXP_PATH +的packageName);
 

使用这样的:

 文件expPathDir =新的文件(root.toString()+ EXP_PATH +的packageName);
文件expPath =新的文件(expPathDir,
    的String.Format(主%D%s.obb,mainVersion,的packageName));
 

这将工作的主要扩展包。你应该有一个类似的方法来访问使用该格式的补丁的String.Format(补丁。%D%s.obb,patchVersion,的packageName)

完整的文件路径应该是这样的。

<$p$p><$c$c>/mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook/main.123./mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook.obb

I have been trying to convert my App to use an APK Expansion file and for some reason this code below cannot find the path to my APK Expansion file ...

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 shows this ...

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

... even though the path does exists and the file is there as demonstrated in this screen shot:

I am pretty certain I do not have a typo and the path exists. So why would expPath.exists() return false.

Thanks for the answer Ted ... but I still get this in the 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

... could it be that I created the directories with Windows and not avd. What would the adb command be to create the dirs and push the APK expansion zip file on to my phone?

解决方案

You need to name the file itself. Instead of this:

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

use this:

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

This will work for a main expansion pack. You should have a similar method for accessing a patch that uses the format String.format("patch.%d.%s.obb", patchVersion, packageName)

The full path to the file should be something like

/mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook/main.123./mnt/sdcard/Android/obb/com.redcricket.GospelofMatthewAudiobook.obb

这篇关于APK扩展文件expPath不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆