SDL: ask for SD card permission right after launch, removed SDL_ANDROID_RequestExternalStorageRuntimePermission() API
This commit is contained in:
@@ -95,6 +95,8 @@ import android.app.PendingIntent;
|
|||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import android.app.UiModeManager;
|
import android.app.UiModeManager;
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
|
import android.content.pm.PermissionInfo;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends Activity
|
public class MainActivity extends Activity
|
||||||
@@ -238,6 +240,25 @@ public class MainActivity extends Activity
|
|||||||
startService(intent);
|
startService(intent);
|
||||||
}
|
}
|
||||||
cloudSave = new CloudSave(this);
|
cloudSave = new CloudSave(this);
|
||||||
|
// Request SD card permission right during start, because game devs don't care about runtime permissions and stuff
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if( android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M )
|
||||||
|
{
|
||||||
|
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_PERMISSIONS | PackageManager.GET_META_DATA);
|
||||||
|
Log.v("SDL", "SD card permission 1: " + getPackageName() + " perms " + info.requestedPermissions + " name " + info.packageName + " ver " + info.versionName);
|
||||||
|
if( info.requestedPermissions != null && Arrays.asList(info.requestedPermissions).contains(Manifest.permission.WRITE_EXTERNAL_STORAGE) )
|
||||||
|
{
|
||||||
|
Log.v("SDL", "SD card permission 4: REQUEST");
|
||||||
|
int permissionCheck = checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||||
|
if (permissionCheck != PackageManager.PERMISSION_GRANTED && !writeExternalStoragePermissionDialogAnswered)
|
||||||
|
{
|
||||||
|
requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpStatusLabel()
|
public void setUpStatusLabel()
|
||||||
|
|||||||
@@ -949,18 +949,6 @@ class DemoRenderer extends GLSurfaceView_SDL.Renderer
|
|||||||
Settings.setConfigOptionFromSDL(option, value);
|
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)
|
private int PowerOf2(int i)
|
||||||
{
|
{
|
||||||
int value = 1;
|
int value = 1;
|
||||||
|
|||||||
@@ -685,11 +685,12 @@ int main(int argc, char* argv[])
|
|||||||
if( evt.key.state == SDL_RELEASED )
|
if( evt.key.state == SDL_RELEASED )
|
||||||
{
|
{
|
||||||
if(evt.key.keysym.sym == SDLK_0)
|
if(evt.key.keysym.sym == SDLK_0)
|
||||||
|
{
|
||||||
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 1);
|
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 1);
|
||||||
|
}
|
||||||
if(evt.key.keysym.sym == SDLK_1)
|
if(evt.key.keysym.sym == SDLK_1)
|
||||||
{
|
{
|
||||||
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 0);
|
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, 0);
|
||||||
SDL_ANDROID_RequestExternalStorageRuntimePermission();
|
|
||||||
}
|
}
|
||||||
if(evt.key.keysym.sym == SDLK_2)
|
if(evt.key.keysym.sym == SDLK_2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -134,9 +134,6 @@ enum {
|
|||||||
/* Set SDL Android-specifc option, such as video depth or mouse emulation mode. Most options require restarting the app. */
|
/* Set SDL Android-specifc option, such as video depth or mouse emulation mode. Most options require restarting the app. */
|
||||||
extern DECLSPEC void SDLCALL SDL_ANDROID_SetConfigOption(int option, int value);
|
extern DECLSPEC void SDLCALL SDL_ANDROID_SetConfigOption(int option, int value);
|
||||||
|
|
||||||
/* Show runtime permission dialog for accessing SD card on Android 6.0 and above */
|
|
||||||
extern DECLSPEC void SDLCALL SDL_ANDROID_RequestExternalStorageRuntimePermission();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ static jmethodID JavaRequestCloudLoad = NULL;
|
|||||||
static jmethodID JavaRequestOpenExternalApp = NULL;
|
static jmethodID JavaRequestOpenExternalApp = NULL;
|
||||||
static jmethodID JavaRequestRestartMyself = NULL;
|
static jmethodID JavaRequestRestartMyself = NULL;
|
||||||
static jmethodID JavaRequestSetConfigOption = NULL;
|
static jmethodID JavaRequestSetConfigOption = NULL;
|
||||||
static jmethodID JavaRequestExternalStorageRuntimePermission = NULL;
|
|
||||||
static int glContextLost = 0;
|
static int glContextLost = 0;
|
||||||
static int showScreenKeyboardDeferred = 0;
|
static int showScreenKeyboardDeferred = 0;
|
||||||
static const char * showScreenKeyboardOldText = "";
|
static const char * showScreenKeyboardOldText = "";
|
||||||
@@ -362,7 +361,6 @@ JAVA_EXPORT_NAME(DemoRenderer_nativeInitJavaCallbacks) ( JNIEnv* env, jobject t
|
|||||||
JavaRequestOpenExternalApp = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "openExternalApp", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
JavaRequestOpenExternalApp = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "openExternalApp", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||||
JavaRequestRestartMyself = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "restartMyself", "(Ljava/lang/String;)V");
|
JavaRequestRestartMyself = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "restartMyself", "(Ljava/lang/String;)V");
|
||||||
JavaRequestSetConfigOption = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setConfigOptionFromSDL", "(II)V");
|
JavaRequestSetConfigOption = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "setConfigOptionFromSDL", "(II)V");
|
||||||
JavaRequestExternalStorageRuntimePermission = (*JavaEnv)->GetMethodID(JavaEnv, JavaRendererClass, "requestExternalStorageRuntimePermissionFromSDL", "()V");
|
|
||||||
|
|
||||||
ANDROID_InitOSKeymap();
|
ANDROID_InitOSKeymap();
|
||||||
}
|
}
|
||||||
@@ -609,11 +607,6 @@ void SDLCALL SDL_ANDROID_OpenExternalWebBrowser(const char *url)
|
|||||||
SDL_ANDROID_OpenExternalApp(NULL, NULL, url);
|
SDL_ANDROID_OpenExternalApp(NULL, NULL, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SDLCALL SDL_ANDROID_RequestExternalStorageRuntimePermission()
|
|
||||||
{
|
|
||||||
(*JavaEnv)->CallVoidMethod( JavaEnv, JavaRenderer, JavaRequestExternalStorageRuntimePermission );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dummy callback for SDL2 to satisfy linker
|
// Dummy callback for SDL2 to satisfy linker
|
||||||
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
|
extern void SDL_Android_Init(JNIEnv* env, jclass cls);
|
||||||
void SDL_Android_Init(JNIEnv* env, jclass cls)
|
void SDL_Android_Init(JNIEnv* env, jclass cls)
|
||||||
|
|||||||
Reference in New Issue
Block a user