Android open InputStream from relative uri to ACTION_OPEN_DOCUMENT?











up vote
0
down vote

favorite












I'am trying to open multiple files relative to a json configuration file in android 4.4 (api level 19),
I used



Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType({mime});
this.startActivityForResult(intent, {code});


to let the user find te configuration file, and from there open multiple files that I know the path from the config file.



But i get



Caused by: java.lang.SecurityException: 
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider
uri content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/{relative file}
requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs


I dont want to use user interfaces to open the other files, so I tried adding the following permissions without getting any results



<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS "/>


I would rather have the files separated and not in a blob or a zip file










share|improve this question
























  • have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
    – jay shah
    Nov 11 at 5:29










  • I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
    – Juan
    Nov 11 at 6:16










  • "I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
    – CommonsWare
    Nov 11 at 12:08















up vote
0
down vote

favorite












I'am trying to open multiple files relative to a json configuration file in android 4.4 (api level 19),
I used



Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType({mime});
this.startActivityForResult(intent, {code});


to let the user find te configuration file, and from there open multiple files that I know the path from the config file.



But i get



Caused by: java.lang.SecurityException: 
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider
uri content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/{relative file}
requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs


I dont want to use user interfaces to open the other files, so I tried adding the following permissions without getting any results



<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS "/>


I would rather have the files separated and not in a blob or a zip file










share|improve this question
























  • have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
    – jay shah
    Nov 11 at 5:29










  • I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
    – Juan
    Nov 11 at 6:16










  • "I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
    – CommonsWare
    Nov 11 at 12:08













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'am trying to open multiple files relative to a json configuration file in android 4.4 (api level 19),
I used



Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType({mime});
this.startActivityForResult(intent, {code});


to let the user find te configuration file, and from there open multiple files that I know the path from the config file.



But i get



Caused by: java.lang.SecurityException: 
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider
uri content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/{relative file}
requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs


I dont want to use user interfaces to open the other files, so I tried adding the following permissions without getting any results



<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS "/>


I would rather have the files separated and not in a blob or a zip file










share|improve this question















I'am trying to open multiple files relative to a json configuration file in android 4.4 (api level 19),
I used



Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType({mime});
this.startActivityForResult(intent, {code});


to let the user find te configuration file, and from there open multiple files that I know the path from the config file.



But i get



Caused by: java.lang.SecurityException: 
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider
uri content://com.android.providers.downloads.documents/document/raw:/storage/emulated/0/Download/{relative file}
requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs


I dont want to use user interfaces to open the other files, so I tried adding the following permissions without getting any results



<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS "/>


I would rather have the files separated and not in a blob or a zip file







android relative-path permission-denied android-contentresolver storage-access-framework






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 6:28

























asked Nov 11 at 5:13









Juan

525




525












  • have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
    – jay shah
    Nov 11 at 5:29










  • I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
    – Juan
    Nov 11 at 6:16










  • "I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
    – CommonsWare
    Nov 11 at 12:08


















  • have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
    – jay shah
    Nov 11 at 5:29










  • I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
    – Juan
    Nov 11 at 6:16










  • "I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
    – CommonsWare
    Nov 11 at 12:08
















have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
– jay shah
Nov 11 at 5:29




have you put the runtime permission for READ_EXTERNAL_STORAGE and MANAGE_DOCUMENTS?
– jay shah
Nov 11 at 5:29












I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
– Juan
Nov 11 at 6:16




I just tried that, I can get READ_EXTERNAL_STORAGE, but not MANAGE_DOCUMENTS, and still get Permission denial. im using minSdkVersion 19, so tried with ActivityCompat.requestPermissions
– Juan
Nov 11 at 6:16












"I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
– CommonsWare
Nov 11 at 12:08




"I'am trying to open multiple files" -- your code is not really related to opening files. If you need to limit the user to files on the filesystem that your app has the ability to access directly, use a file chooser library, not a system Intent like ACTION_OPEN_DOCUMENT.
– CommonsWare
Nov 11 at 12:08












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.



You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).






share|improve this answer





















  • ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
    – Juan
    Nov 11 at 6:25






  • 1




    Correct, there's no equivalent pre-API 21.
    – ianhanniballake
    Nov 11 at 7:17











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',
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%2f53246026%2fandroid-open-inputstream-from-relative-uri-to-action-open-document%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








up vote
2
down vote



accepted










ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.



You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).






share|improve this answer





















  • ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
    – Juan
    Nov 11 at 6:25






  • 1




    Correct, there's no equivalent pre-API 21.
    – ianhanniballake
    Nov 11 at 7:17















up vote
2
down vote



accepted










ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.



You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).






share|improve this answer





















  • ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
    – Juan
    Nov 11 at 6:25






  • 1




    Correct, there's no equivalent pre-API 21.
    – ianhanniballake
    Nov 11 at 7:17













up vote
2
down vote



accepted







up vote
2
down vote



accepted






ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.



You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).






share|improve this answer












ACTION_OPEN_DOCUMENT only gives you access to exactly the file (or files, if you use EXTRA_ALLOW_MULTIPLE) that the user selects.



You can use ACTION_OPEN_DOCUMENT_TREE to allow the user to select a folder - you'll then get access to all files in that folder (and their subfolders).







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 11 at 5:52









ianhanniballake

101k14210222




101k14210222












  • ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
    – Juan
    Nov 11 at 6:25






  • 1




    Correct, there's no equivalent pre-API 21.
    – ianhanniballake
    Nov 11 at 7:17


















  • ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
    – Juan
    Nov 11 at 6:25






  • 1




    Correct, there's no equivalent pre-API 21.
    – ianhanniballake
    Nov 11 at 7:17
















ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
– Juan
Nov 11 at 6:25




ACTION_OPEN_DOCUMENT_TREE was added in API level 21, Forgot to specify, but I'm using minSdkVersion 19, so I cant use that, I think I'll just use zip files :'(
– Juan
Nov 11 at 6:25




1




1




Correct, there's no equivalent pre-API 21.
– ianhanniballake
Nov 11 at 7:17




Correct, there's no equivalent pre-API 21.
– ianhanniballake
Nov 11 at 7:17


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53246026%2fandroid-open-inputstream-from-relative-uri-to-action-open-document%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python