requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()












1















When I'm going select a file from all downloads folder and then getting file path from uri using content provider getting following permission denied issue below



Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1092 from pid=31615, uid=10228 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()


using following code



String contentUriPrefixesToTry = new String{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
final String id = DocumentsContract.getDocumentId(uri);
String path = null;
for (String uriPath : contentUriPrefixesToTry) {
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse(uriPath), Long.valueOf(id));
String lastPathSagment = uri.getLastPathSegment();
InputStream inputStream = context.getContentResolver().openInputStream(uri);
File file = new File(context.getCacheDir().getAbsolutePath() + "/" + lastPathSagment);
writeFile(inputStream, file);
path = file.getAbsolutePath();
if (path != null) {
return path;
}
}









share|improve this question

























  • Where is uri coming from? How are you getting that value?

    – CommonsWare
    Jan 1 at 11:48











  • @CommonsWare uri is content://downloads/all_downloads/1234

    – JosephM
    Jan 1 at 11:50













  • That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

    – CommonsWare
    Jan 1 at 11:52











  • @CommonsWare uri is not hard coded its example uri, i have updated question please check

    – JosephM
    Jan 1 at 11:54








  • 1





    If your target version above >=24 then you need to use FileProvider.

    – Piyush
    Jan 1 at 12:03


















1















When I'm going select a file from all downloads folder and then getting file path from uri using content provider getting following permission denied issue below



Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1092 from pid=31615, uid=10228 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()


using following code



String contentUriPrefixesToTry = new String{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
final String id = DocumentsContract.getDocumentId(uri);
String path = null;
for (String uriPath : contentUriPrefixesToTry) {
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse(uriPath), Long.valueOf(id));
String lastPathSagment = uri.getLastPathSegment();
InputStream inputStream = context.getContentResolver().openInputStream(uri);
File file = new File(context.getCacheDir().getAbsolutePath() + "/" + lastPathSagment);
writeFile(inputStream, file);
path = file.getAbsolutePath();
if (path != null) {
return path;
}
}









share|improve this question

























  • Where is uri coming from? How are you getting that value?

    – CommonsWare
    Jan 1 at 11:48











  • @CommonsWare uri is content://downloads/all_downloads/1234

    – JosephM
    Jan 1 at 11:50













  • That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

    – CommonsWare
    Jan 1 at 11:52











  • @CommonsWare uri is not hard coded its example uri, i have updated question please check

    – JosephM
    Jan 1 at 11:54








  • 1





    If your target version above >=24 then you need to use FileProvider.

    – Piyush
    Jan 1 at 12:03
















1












1








1








When I'm going select a file from all downloads folder and then getting file path from uri using content provider getting following permission denied issue below



Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1092 from pid=31615, uid=10228 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()


using following code



String contentUriPrefixesToTry = new String{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
final String id = DocumentsContract.getDocumentId(uri);
String path = null;
for (String uriPath : contentUriPrefixesToTry) {
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse(uriPath), Long.valueOf(id));
String lastPathSagment = uri.getLastPathSegment();
InputStream inputStream = context.getContentResolver().openInputStream(uri);
File file = new File(context.getCacheDir().getAbsolutePath() + "/" + lastPathSagment);
writeFile(inputStream, file);
path = file.getAbsolutePath();
if (path != null) {
return path;
}
}









share|improve this question
















When I'm going select a file from all downloads folder and then getting file path from uri using content provider getting following permission denied issue below



Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/1092 from pid=31615, uid=10228 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()


using following code



String contentUriPrefixesToTry = new String{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
final String id = DocumentsContract.getDocumentId(uri);
String path = null;
for (String uriPath : contentUriPrefixesToTry) {
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse(uriPath), Long.valueOf(id));
String lastPathSagment = uri.getLastPathSegment();
InputStream inputStream = context.getContentResolver().openInputStream(uri);
File file = new File(context.getCacheDir().getAbsolutePath() + "/" + lastPathSagment);
writeFile(inputStream, file);
path = file.getAbsolutePath();
if (path != null) {
return path;
}
}






android uri android-contentprovider android-permissions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 11:58







JosephM

















asked Jan 1 at 11:46









JosephMJosephM

1,7954823




1,7954823













  • Where is uri coming from? How are you getting that value?

    – CommonsWare
    Jan 1 at 11:48











  • @CommonsWare uri is content://downloads/all_downloads/1234

    – JosephM
    Jan 1 at 11:50













  • That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

    – CommonsWare
    Jan 1 at 11:52











  • @CommonsWare uri is not hard coded its example uri, i have updated question please check

    – JosephM
    Jan 1 at 11:54








  • 1





    If your target version above >=24 then you need to use FileProvider.

    – Piyush
    Jan 1 at 12:03





















  • Where is uri coming from? How are you getting that value?

    – CommonsWare
    Jan 1 at 11:48











  • @CommonsWare uri is content://downloads/all_downloads/1234

    – JosephM
    Jan 1 at 11:50













  • That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

    – CommonsWare
    Jan 1 at 11:52











  • @CommonsWare uri is not hard coded its example uri, i have updated question please check

    – JosephM
    Jan 1 at 11:54








  • 1





    If your target version above >=24 then you need to use FileProvider.

    – Piyush
    Jan 1 at 12:03



















Where is uri coming from? How are you getting that value?

– CommonsWare
Jan 1 at 11:48





Where is uri coming from? How are you getting that value?

– CommonsWare
Jan 1 at 11:48













@CommonsWare uri is content://downloads/all_downloads/1234

– JosephM
Jan 1 at 11:50







@CommonsWare uri is content://downloads/all_downloads/1234

– JosephM
Jan 1 at 11:50















That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

– CommonsWare
Jan 1 at 11:52





That didn't answer my questions. After all, you aren't hard-coding that Uri, since it will not exist on all devices. So, somehow, you are getting that value at runtime. How are you doing this?

– CommonsWare
Jan 1 at 11:52













@CommonsWare uri is not hard coded its example uri, i have updated question please check

– JosephM
Jan 1 at 11:54







@CommonsWare uri is not hard coded its example uri, i have updated question please check

– JosephM
Jan 1 at 11:54






1




1





If your target version above >=24 then you need to use FileProvider.

– Piyush
Jan 1 at 12:03







If your target version above >=24 then you need to use FileProvider.

– Piyush
Jan 1 at 12:03














1 Answer
1






active

oldest

votes


















0














Your code is 'trying' to access that directory to see if it exists, and even open an inputstream to get the supposed File. If the directory doesn't exist Android will be displeased with you and tell you that you're not allowed to access that dir.
No need to request permission as the dir does not exist.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995161%2frequires-android-permission-access-all-downloads-or-granturipermission%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your code is 'trying' to access that directory to see if it exists, and even open an inputstream to get the supposed File. If the directory doesn't exist Android will be displeased with you and tell you that you're not allowed to access that dir.
    No need to request permission as the dir does not exist.






    share|improve this answer




























      0














      Your code is 'trying' to access that directory to see if it exists, and even open an inputstream to get the supposed File. If the directory doesn't exist Android will be displeased with you and tell you that you're not allowed to access that dir.
      No need to request permission as the dir does not exist.






      share|improve this answer


























        0












        0








        0







        Your code is 'trying' to access that directory to see if it exists, and even open an inputstream to get the supposed File. If the directory doesn't exist Android will be displeased with you and tell you that you're not allowed to access that dir.
        No need to request permission as the dir does not exist.






        share|improve this answer













        Your code is 'trying' to access that directory to see if it exists, and even open an inputstream to get the supposed File. If the directory doesn't exist Android will be displeased with you and tell you that you're not allowed to access that dir.
        No need to request permission as the dir does not exist.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 9 at 15:20









        BruceHabsBruceHabs

        111




        111
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53995161%2frequires-android-permission-access-all-downloads-or-granturipermission%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            'app-layout' is not a known element: how to share Component with different Modules

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            WPF add header to Image with URL pettitions [duplicate]