Is it possible to provide a zipped file in FileProvider, of a file that doesn't really exist?
Background
I wish to be able to share some files (via a send intent) as a single compressed file, via FileProvider.
For the intent, all you do is add the ArrayList<Uri>
as a parameter, as such:
ArrayList<Uri> uris = MyFileProvider.prepareFileProviderFiles(...)
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
The problem
A FileProvider can be used to deliver real files to outside apps.
I don't want to have some junk files (the compressed ones, which are meant just for sharing) in my app staying around without any purpose, in case the app that used them has finished, crashed or stopped for some reason.
What I've found
According to the API of FileProvider, I'm supposed to implement real files handling:
By default, FileProvider automatically returns the
ParcelFileDescriptor for a file associated with a content:// Uri. To
get the ParcelFileDescriptor, call ContentResolver.openFileDescriptor.
To override this method, you must provide your own subclass of
FileProvider.
So it returns a ParcelFileDescriptor, but according to all of the functions to create ParcelFileDescriptor , I need a real file:
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int)
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int,%20android.os.Handler,%20android.os.ParcelFileDescriptor.OnCloseListener)
The questions
Is it possible to have it offer a file that doesn't really exist, but is actually a compressed one of a different file/s? A stream of the zipped file, perhaps?
If this is not possible, is there any way for me to avoid having those junk files? Meaning that I would know for sure that it's safe to delete the compressed file/s that I've shared in the past?
If even that isn't possible, how could I decide when it's ok to delete them? Just putting them in the cache folder? I remember that the cache folder doesn't really automatically get handled nicely by the OS, removing old files when needed. Isn't it still correct?

add a comment |
Background
I wish to be able to share some files (via a send intent) as a single compressed file, via FileProvider.
For the intent, all you do is add the ArrayList<Uri>
as a parameter, as such:
ArrayList<Uri> uris = MyFileProvider.prepareFileProviderFiles(...)
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
The problem
A FileProvider can be used to deliver real files to outside apps.
I don't want to have some junk files (the compressed ones, which are meant just for sharing) in my app staying around without any purpose, in case the app that used them has finished, crashed or stopped for some reason.
What I've found
According to the API of FileProvider, I'm supposed to implement real files handling:
By default, FileProvider automatically returns the
ParcelFileDescriptor for a file associated with a content:// Uri. To
get the ParcelFileDescriptor, call ContentResolver.openFileDescriptor.
To override this method, you must provide your own subclass of
FileProvider.
So it returns a ParcelFileDescriptor, but according to all of the functions to create ParcelFileDescriptor , I need a real file:
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int)
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int,%20android.os.Handler,%20android.os.ParcelFileDescriptor.OnCloseListener)
The questions
Is it possible to have it offer a file that doesn't really exist, but is actually a compressed one of a different file/s? A stream of the zipped file, perhaps?
If this is not possible, is there any way for me to avoid having those junk files? Meaning that I would know for sure that it's safe to delete the compressed file/s that I've shared in the past?
If even that isn't possible, how could I decide when it's ok to delete them? Just putting them in the cache folder? I remember that the cache folder doesn't really automatically get handled nicely by the OS, removing old files when needed. Isn't it still correct?

add a comment |
Background
I wish to be able to share some files (via a send intent) as a single compressed file, via FileProvider.
For the intent, all you do is add the ArrayList<Uri>
as a parameter, as such:
ArrayList<Uri> uris = MyFileProvider.prepareFileProviderFiles(...)
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
The problem
A FileProvider can be used to deliver real files to outside apps.
I don't want to have some junk files (the compressed ones, which are meant just for sharing) in my app staying around without any purpose, in case the app that used them has finished, crashed or stopped for some reason.
What I've found
According to the API of FileProvider, I'm supposed to implement real files handling:
By default, FileProvider automatically returns the
ParcelFileDescriptor for a file associated with a content:// Uri. To
get the ParcelFileDescriptor, call ContentResolver.openFileDescriptor.
To override this method, you must provide your own subclass of
FileProvider.
So it returns a ParcelFileDescriptor, but according to all of the functions to create ParcelFileDescriptor , I need a real file:
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int)
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int,%20android.os.Handler,%20android.os.ParcelFileDescriptor.OnCloseListener)
The questions
Is it possible to have it offer a file that doesn't really exist, but is actually a compressed one of a different file/s? A stream of the zipped file, perhaps?
If this is not possible, is there any way for me to avoid having those junk files? Meaning that I would know for sure that it's safe to delete the compressed file/s that I've shared in the past?
If even that isn't possible, how could I decide when it's ok to delete them? Just putting them in the cache folder? I remember that the cache folder doesn't really automatically get handled nicely by the OS, removing old files when needed. Isn't it still correct?

Background
I wish to be able to share some files (via a send intent) as a single compressed file, via FileProvider.
For the intent, all you do is add the ArrayList<Uri>
as a parameter, as such:
ArrayList<Uri> uris = MyFileProvider.prepareFileProviderFiles(...)
sharingIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
The problem
A FileProvider can be used to deliver real files to outside apps.
I don't want to have some junk files (the compressed ones, which are meant just for sharing) in my app staying around without any purpose, in case the app that used them has finished, crashed or stopped for some reason.
What I've found
According to the API of FileProvider, I'm supposed to implement real files handling:
By default, FileProvider automatically returns the
ParcelFileDescriptor for a file associated with a content:// Uri. To
get the ParcelFileDescriptor, call ContentResolver.openFileDescriptor.
To override this method, you must provide your own subclass of
FileProvider.
So it returns a ParcelFileDescriptor, but according to all of the functions to create ParcelFileDescriptor , I need a real file:
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int)
https://developer.android.com/reference/android/os/ParcelFileDescriptor#open(java.io.File,%20int,%20android.os.Handler,%20android.os.ParcelFileDescriptor.OnCloseListener)
The questions
Is it possible to have it offer a file that doesn't really exist, but is actually a compressed one of a different file/s? A stream of the zipped file, perhaps?
If this is not possible, is there any way for me to avoid having those junk files? Meaning that I would know for sure that it's safe to delete the compressed file/s that I've shared in the past?
If even that isn't possible, how could I decide when it's ok to delete them? Just putting them in the cache folder? I remember that the cache folder doesn't really automatically get handled nicely by the OS, removing old files when needed. Isn't it still correct?


asked Jan 1 at 18:22


android developerandroid developer
54.3k98472877
54.3k98472877
add a comment |
add a comment |
0
active
oldest
votes
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997852%2fis-it-possible-to-provide-a-zipped-file-in-fileprovider-of-a-file-that-doesnt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997852%2fis-it-possible-to-provide-a-zipped-file-in-fileprovider-of-a-file-that-doesnt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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