SDL: request Marshmallow SD card runtime permission using SDL_ANDROID_RequestExternalStorageRuntimePermission()
This commit is contained in:
@@ -53,6 +53,9 @@ import android.text.SpannedString;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
|
||||
class CountingInputStream extends BufferedInputStream
|
||||
{
|
||||
@@ -328,6 +331,19 @@ class DataDownloader extends Thread
|
||||
Status.setText( downloadCount + "/" + downloadTotal + ": " + res.getString(R.string.connecting_to, url) );
|
||||
if( url.indexOf("obb:") == 0 ) // APK expansion file provided by Google Play
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
||||
{
|
||||
int permissionCheck = Parent.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permissionCheck != PackageManager.PERMISSION_GRANTED && !Parent.writeExternalStoragePermissionDialogAnswered)
|
||||
{
|
||||
Parent.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
while( !Parent.writeExternalStoragePermissionDialogAnswered )
|
||||
{
|
||||
try{ Thread.sleep(300); } catch (InterruptedException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
url = getObbFilePath(url);
|
||||
InputStream stream1 = null;
|
||||
try {
|
||||
|
||||
@@ -1580,6 +1580,11 @@ public class MainActivity extends Activity
|
||||
{
|
||||
Log.i("SDL", "libSDL: Record audio permission: " + (grantResults[0] == PackageManager.PERMISSION_GRANTED ? "GRANTED" : "DENIED"));
|
||||
}
|
||||
if (Manifest.permission.WRITE_EXTERNAL_STORAGE.equals(permissions[0]))
|
||||
{
|
||||
Log.i("SDL", "libSDL: Write external storage permission: " + (grantResults[0] == PackageManager.PERMISSION_GRANTED ? "GRANTED" : "DENIED"));
|
||||
writeExternalStoragePermissionDialogAnswered = true;
|
||||
}
|
||||
}
|
||||
|
||||
public FrameLayout getVideoLayout() { return _videoLayout; }
|
||||
@@ -1620,6 +1625,7 @@ public class MainActivity extends Activity
|
||||
|
||||
public LinkedList<Integer> textInput = new LinkedList<Integer> ();
|
||||
public static MainActivity instance = null;
|
||||
public boolean writeExternalStoragePermissionDialogAnswered = false;
|
||||
}
|
||||
|
||||
// *** HONEYCOMB / ICS FIX FOR FULLSCREEN MODE, by lmak ***
|
||||
|
||||
@@ -63,6 +63,8 @@ import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.Display;
|
||||
import android.net.Uri;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
|
||||
class Mouse
|
||||
@@ -947,6 +949,18 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
||||
Settings.setConfigOptionFromSDL(option, value);
|
||||
}
|
||||
|
||||
public void requestExternalStorageRuntimePermissionFromSDL()
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
||||
{
|
||||
int permissionCheck = context.checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
if (permissionCheck != PackageManager.PERMISSION_GRANTED && !context.writeExternalStoragePermissionDialogAnswered)
|
||||
{
|
||||
context.requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int PowerOf2(int i)
|
||||
{
|
||||
int value = 1;
|
||||
|
||||
Reference in New Issue
Block a user