How can get read and write permission in android 11,yes friends I have finally get Storage permission in android 11 , without MANAGE_EXTERNAL_STORAGE

Viewed 100

How can i let ACTION_OPEN_DOCUMENT_TREE

Make Method and put this code on that

 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q)
{
    StorageManager sm = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);

    Intent intent = sm.getPrimaryStorageVolume().createOpenDocumentTreeIntent();
    //String startDir = "Android";
    //String startDir = "Download"; // Not choosable on an Android 11 device
    //String startDir = "DCIM";
    //String startDir = "DCIM/Camera";  // replace "/", "%2F"
    //String startDir = "DCIM%2FCamera";
   // String startDir = "Documents";
    String startDir = "Android/data";

    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/");

    startDir = startDir.replace("/", "%2F");

    scheme += "%3A" + startDir;

    uri = Uri.parse(scheme);

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

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

    ((Activity) context).startActivityForResult(intent, REQUEST_ACTION_OPEN_DOCUMENT_TREE);

    return;
}

This is my app link you can see how i can work on that https://play.google.com/store/apps/details?id=com.raavi.whatsappstatusessaver

0 Answers
Related