2013-03-21 162 views
0

我一直想我的應用程序轉換爲使用APK擴展文件,由於某種原因,下面這段代碼無法找到路徑到我的APK擴展文件...APK擴展文件expPath不存在

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 

...即使路徑不存在,該文件是那裏證明在這個屏幕截圖:

enter image description here 我很確定我沒有錯別字和路徑存在。那麼爲什麼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目錄和不avdadb命令是如何創建目錄並將APK擴展zip文件推送到我的手機上的?

+0

我發現'adb.exe'在'C:\用戶\小兵\ AppData \ Local \ Android \ android-sdk \ platform-tools>' – 2013-03-21 05:25:51

+0

我試過這個命令:'C:\ Users \ dogface \ AppData \ Local \ Android \ android-sdk \ platform-tools> adb.exe push c :\ main.1.com.redcricket.GospelofMatthewAudiobook.obb到/ mnt/SD卡/安卓/ OBB/COM .redcricket.GospelofMatthewAudiobook \ main.1.com.redcricket.GospelofMatthewAudiob ook.obb 無法複製「C:\ main.1 .com.redcricket.GospelofMatthewAudiobook.obb」到 '的/ mnt/ SD卡/ Android設備/ OBB/com.redcricket.GospelofMatthewAudiobook \ main.1.com.redcricket .GospelofMatthewAudiobook.obb':權限被拒絕 C:\用戶\ dogface \ AppData \ Local \ Android \ android-sdk \ platform-tools>' – 2013-03-21 05:43:52

回答

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 
+0

不應該**%i **是__%d__? – java 2015-11-05 22:08:09

+0

你的答案也可以應用於我的答案?但它沒有奏效。 http://stackoverflow.com/questions/33553722/obb-opaque-binary-blobb-getmountedobbpath-returning-null – java 2015-11-05 22:14:16

+0

@java - 是的,'%i'應該是'%d'。謝謝你的收穫。我會看看你的其他問題。如果你花時間:-) – 2015-11-06 00:11:23