Specific folder permission Android 11

The solution was provided just a few posts below.

I understand.

Please read #103 post. Please I badly need this

https://community.kodular.io/t/saf-app-inventor-implementation-of-storage-access-framework/144020/103?u=samirtalukder

Sorry for disturbing you. Please teach me how to do it

Sorry, you don’t.
I can’t provide you any block until you show me what you have tried (blocks).


SAF is for making files accessible to your app, though this extension provides methods to read/write to them. Since document is accessible to your app you can do many things with that, but not with this extension. :sweat_smile:

1 Like

I know i am not using your this extension. But I am using your Filetools extension and File component
As you are a file Expert i thought you could help me
Here is my example blocks this is not the original app or block

Taking permission of all files is not a good idea

Can you teach me how to get specific folder permission in android 11 like this?

Please read the first post to know how this extension works.

I read that before. I know I am asking something not related to this extension. I was created a post for that problem but moderator unlisted that post because i asked you here.

Can you solve my problem? As you are a storage Expert.

I just need to know how to get permission of specific folder of other app Private folder in Android 11

That is the problem when you start posting in multiple places. Let’s see if i can fix that.

How to do it in koduler?

1

okay so all of these people saying you cannot access app specific folders, are absolutely wrong, heres how u do it:

Step 1: get the permission of the folder you want,

public void openDirectory() {

String path = Environment.getExternalStorageDirectory() + "/Android/data/com.pubg.krmobile/whatever folder you want to access";
File file = new File(path);
String startDir, secondDir, finalDirPath;

if (file.exists()) {
    startDir = "Android%2Fdata%2Fcom.pubg.krmobile%2Fthefilder%2Fsubfolder%2Fdeepersubfolder";
} 

StorageManager sm = (StorageManager) getSystemService(Context.STORAGE_SERVICE);

Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();


Uri uri = intent.getParcelableExtra("android.provider.extra.INITIAL_URI");

String scheme = uri.toString();

Log.d("TAG", "INITIAL_URI scheme: " + scheme);

scheme = scheme.replace("/root/", "/document/");

finalDirPath = scheme + "%3A" + startDir;

uri = Uri.parse(finalDirPath);

intent.putExtra("android.provider.extra.INITIAL_URI", uri);

Log.d("TAG", "uri: " + uri.toString());

try {
    startActivityForResult(intent, 6);
} catch (ActivityNotFoundException ignored) {

}}

step 2: write an onactivityresult to get the path

public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    
    if (resultCode == RESULT_OK) {
        if (data != null) {
            uri = data.getData();
            if (uri.getPath().endsWith(".Statuses")) {
                Log.d("TAG", "onActivityResult: " + uri.getPath());
                final int takeFlags = data.getFlags()
                                              & (Intent.FLAG_GRANT_READ_URI_PERMISSION);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                    getContentResolver().takePersistableUriPermission(uri, takeFlags);
                }
                
                // these are my SharedPerfernce values for remembering the path
                prefHelper.setIsScopePermissionGranted(true);
                prefHelper.setSavedRoute(uri.toString());
                
                // save any boolean in pref if user given the right path so we can use the path 
                // in future and avoid to ask permission more than one time
                
                startActivity(new Intent(this, MainDashboardActivity.class));
                finish();
                
            } else {
                // dialog when user gave wrong path
                showWrongPathDialog();
            }
            
        }
    }}

step 3: Get the files one by one from here

 if (Build.VERSION.SDK_INT >= 29) {
            // uri is the path which we've saved in our shared pref
            DocumentFile fromTreeUri = DocumentFile.fromTreeUri(context, uri);
            DocumentFile[] documentFiles = fromTreeUri.listFiles();
            
            
            for (int i = 0; i < documentFiles.length; i++) {
                documentFiles[i].getUri().toString() //uri of the document
                }
            }
        }

and voila, you now have access to that folder using the path saved in shared prefrences

well, I’m confused… your question is how to do it in Kodular, isn’t it?
so to access files, which are stored outside of the app or the shared directories, you can use the SAF extension

And you provide some code snippets which show, how to do it?
Can you please provide a link to those code snippets?

Taifun

2 Likes

I want to access: Android/data/com.other.app/some files
I want want to read data of other app
Here is the link to do it in Android studio

…and have you read the article you provided ?

Yes but as I am not an Developer I can’t understand anything. They said that We can access app specific folder of other app by that process.
Sorry, I am saying it here.
Can you help me here?
I also have problem with ads. My app has 1000 downloads now in Galaxy Store​:slightly_smiling_face:

Please don’t spam a topic by bringing up unrelated queries.

Please give me that extension
@SamirTalukder
Thanks in advance

All files access is dangerous. Google don’t approve it for normal apps

I will use that extension for my personal use . Please give me that extension.
Thanks in advance

:upside_down_face:

No.

But I think, it won’t even work with MANAGE_EXTERNAL_STORAGE permission.
I didn’t try it, but I’m pretty sure. Try it and report.