Android 6.0 permissions and installing OBB

I have permission issue on Android 6.0 and above.

The game I'm working on uses permission WRITE_EXTERNAL_STORAGE. On Android 6.0 and above, a warning is issued that asks the user to allow it.

I received a request to get rid of this warning, which means that the game can no longer use WRITE_EXTERNAL_STORAGE.

Technically, the game does not write or read external storage anywhere now. All saved and cached files are stored in the application directory (/storage/emulated/0/Android/data/com.company.productname) But the game must read (and sometimes load) the OBB file, which is stored in the / storage / emulated / 0 directory /Android/obb/com.company.productname.

The game has access to this directory, even without WRITE_EXTERNAL_STORAGE or READ_EXTERNAL_STORAGE on devices:

  • Motorola Nexus 6
  • LG Nexus 5

But it seems he does not have access to this directory:

  • Samsung Galaxy S5, S6 and S7
  • Nvidia Shield Tablet

I even tested it with Alpha Tests to simulate downloading a game from a store.

When permission is granted for storage (through the application settings), everything works fine.

How is OBB mounted?

In Unreal Engine 4, which I use, uses the C open () function to process the OBB file:

int32 Handle = open(LocalPath, O_RDONLY); 

Where LocalPath is the full path to the obb file: /storage/emulated/0/Android/obb/com.company.productname/main.10003.com.company.productname.obb

Questions:

  • Do you need READ / WRITE _EXTERNAL_STORAGE to read and download the OBB file?
  • If so, how can I get rid of the warning that asks the user for permission.
  • If not, why is the Samsung Galaxy S Series creating such problems?
+7
android android-permissions android-expansion-files
source share
4 answers

Well, it looks like the problem was pointed out somewhere else, but I could not find it because I did not know that it was the exact problem ...

https://code.google.com/p/android/issues/detail?id=197287

API23, for some reason, set the OBB user to root, and not to the correct user, and because of this, the application does not have access to it.

After rebooting the device, everything works fine.

There is no clear path for this at this moment.

Thanks @Larry for providing all the necessary and useful information :)

+8
source share

We invite you to check whether your application is allowed from the store.

+2
source share

Thanks to @Larry for pointing out the right solution.

For those who are wondering why the AOSP APK Expansion Support libray does not work without permission, here is a modified APKExpansionSupport.java

 package com.android.vending.expansion.zipfile; /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.io.IOException; import java.util.Vector; import android.content.Context; public class APKExpansionSupport { public static String[] getAPKExpansionFiles(Context ctx, int mainVersion, int patchVersion) { String packageName = ctx.getPackageName(); Vector<String> ret = new Vector<>(2); File expPath = ctx.getObbDir(); // Check that expansion file path exists if (expPath.exists()) { if ( mainVersion > 0 ) { String strMainPath = expPath + File.separator + "main." + mainVersion + "." + packageName + ".obb"; File main = new File(strMainPath); if ( main.isFile() ) { ret.add(strMainPath); } } if ( patchVersion > 0 ) { String strPatchPath = expPath + File.separator + "patch." + mainVersion + "." + packageName + ".obb"; File main = new File(strPatchPath); if ( main.isFile() ) { ret.add(strPatchPath); } } } String[] retArray = new String[ret.size()]; ret.toArray(retArray); return retArray; } public static ZipResourceFile getResourceZipFile(String[] expansionFiles) throws IOException { ZipResourceFile apkExpansionFile = null; for (String expansionFilePath : expansionFiles) { if ( null == apkExpansionFile ) { apkExpansionFile = new ZipResourceFile(expansionFilePath); } else { apkExpansionFile.addPatchFile(expansionFilePath); } } return apkExpansionFile; } public static ZipResourceFile getAPKExpansionZipFile(Context ctx, int mainVersion, int patchVersion) throws IOException{ String[] expansionFiles = getAPKExpansionFiles(ctx, mainVersion, patchVersion); return getResourceZipFile(expansionFiles); } } 
+1
source share

Providing an answer here based on the above comment topic. The problem is that LocalPath provided. On Android, file system paths are incompatible between different manufacturers, and you should not make any assumptions about storage paths.

So, instead (just sample code):

 public class MyActivity extends Activity { static final String LocalPath = "/storage/emulated/0/Android/obb/com.company.productname/main.10003.com.company.p‌​roductname.obb "; ... } 

You need to do something like this:

 public class MyActivity extends Activity { File mObb; ... public void onCreate(Bundle savedInstanceState) { super.onCreate(); ... mObb = new File(getObbDir(), getPackageName() + ".obb"); // Get the path for passing to UE4 later String LocalPath = mObb.getAbsolutePath(); } 

This ensures that your code gets the correct OBB location for your application on the primary external memory for this device. Then you can save the OBB there and later, when your application starts to run UE4, it can point directly to the file.

The location of the application on the primary external memory for OBB (and other files) does not require read and write permissions for this application. If the path to the external storage is not the only one created by the above methods, the permission WRITE_EXTERNAL_STORAGE is required to write data.

0
source share

All Articles