N
N
Nikita Derbenev2020-08-21 08:45:06
Java
Nikita Derbenev, 2020-08-21 08:45:06

Android NDK writing files to /sdcard/?

I am porting my game to android and am having trouble making saves. The fact is that when installing on android 9, the list of permissions is not shown (they are written in the manifest), and I have to MANUALLY enable this permission in the SETTINGS. I tried to write like this (in java):

such code

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();
    }
}

, but the compiler gave the following errors:
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.

I even tried to shove this function into the sdl2 java sources, but the following errors appear:
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.

What is the correct way to request write permission (preferably in C++)?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question