Android API 23 XAPK validation failed due to OBB permissions

So sorry for the late response, here is what I have done…

I have edited DownloaderActivity.java.template which is mostly located in C:\Program Files\Epic Games\UE_4.16\Engine\Build\Android\Java\JavaTemplates

  • Created a new Java method called doOnCreate()

  • Took all the contents of onCreate method, pasted them into doOnCreate() and called it from onCreate

  • In method doOnCreate() I have added the following code on top to request for Write permission if it was not already granted

     	if (android.support.v4.content.ContextCompat.checkSelfPermission(_download,
                 android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
         != android.content.pm.PackageManager.PERMISSION_GRANTED) {
     			
     			android.support.v4.app.ActivityCompat.requestPermissions(_download,
                 new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE},
                 MY_PERMISSIONS_REQUEST_STORAGE_ACCESS);
     		
     	}
    
  • MY_PERMISSIONS_REQUEST_STORAGE_ACCESS is an integer constant that you need to declare first and assign an integer value to it.

  • Created another override method to check the outcome provided by user for the permission request whether it is granted or not. if granted, calls doOnCreate() method again.

          @Override
     	public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
     		
     		switch (requestCode) {
     			case MY_PERMISSIONS_REQUEST_STORAGE_ACCESS: {
     				// If request is cancelled, the result arrays are empty.
     				if (grantResults.length > 0
     					&& grantResults[0] == android.content.pm.PackageManager.PERMISSION_GRANTED) {
     
     					doOnCreate();
     
     				} else {
     
     					this.finish();
     				}
     				return;
     			}
     		}		
     	}
    
  • That’s it, I hope this helps. This is the basic implementation, you can handle the rejection as you see fit. These information for granting storage access can be referred to in Android documentation for API 23+. Full Java file is also attached (UE V4.16) link text .