Я портирую свою игру на android и столкнулся с трудностями, что надо сделать сохранения. Дело в том, что при установке на android 9 не показывается список разрешений (в манифесте они написаны) , и мне приходится ВРУЧНУЮ В НАСТРОЙКАХ включать это разрешение. Я пробовал писать так(на java):
такой код
package com.habebu.podval;
import org.libsdl.app.SDLActivity;
public class podvalActivity extends SDLActivity{
@overrive:
public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG,"Permission is granted");
return true;
} else {
Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
}
else { //permission is automatically granted on sdk<23 upon installation
Log.v(TAG,"Permission is granted");
return true;
}
}
public void onCreate(Bundle savedInstanceState) {
isStoragePermissionGranted();
}
}
, но компилятор выдавал такие ошибки:
errors> Task :app:compileDebugJavaWithJavac FAILED
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:25: error: cannot find symbol
public void onCreate(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class podvalActivity
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:8: error: package Build does not exist
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:8: error: package Build does not exist
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:10: error: cannot find symbol
== PackageManager.PERMISSION_GRANTED) {
^
symbol: variable PackageManager
location: class podvalActivity
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:11: error: TAG has private access in SDLActivity
Log.v(TAG,"Permission is granted");
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:11: error: cannot find symbol
Log.v(TAG,"Permission is granted");
^
symbol: variable Log
location: class podvalActivity
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:15: error: TAG has private access in SDLActivity
Log.v(TAG,"Permission is revoked");
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:15: error: cannot find symbol
Log.v(TAG,"Permission is revoked");
^
symbol: variable Log
location: class podvalActivity
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:16: error: package Manifest does not exist
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:16: error: cannot find symbol
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
^
symbol: variable ActivityCompat
location: class podvalActivity
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:21: error: TAG has private access in SDLActivity
Log.v(TAG,"Permission is granted");
^
/media/nikita/Files/Android/podval/app/src/main/java/com/habebu/podval/podvalActivity.java:21: error: cannot find symbol
Log.v(TAG,"Permission is granted");
^
symbol: variable Log
location: class podvalActivity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /media/nikita/Files/Android/podval/app/src/main/java/org/libsdl/app/SDL.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
12 errors
FAILURE: Build failed with an exception.
Пробовал даже эту функцию пихать в java-исходники sdl2, но появляются такие ошибки:
errors> Task :app:compileDebugJavaWithJavac FAILED
/media/nikita/Files/Android/podval/app/src/main/java/org/libsdl/app/SDLActivity.java:107: error: package Manifest does not exist
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
^
/media/nikita/Files/Android/podval/app/src/main/java/org/libsdl/app/SDLActivity.java:107: error: cannot find symbol
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
^
symbol: variable ActivityCompat
location: class SDLActivity
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /media/nikita/Files/Android/podval/app/src/main/java/org/libsdl/app/SDL.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Как правильно запросить разрешение на запись (желательно на с++)?