Answer the question
In order to leave comments, you need to log in
How to get the full path to a file via Uri?
Good afternoon, I'm new to android development, I have such a task, I need to be able to share files from the phone gallery through my application, then I have to send these files to the back via http,
I added a filter file to the manifest, the application appeared in shar menu.
Created an Activity and methods, the first one that receives files, the second one that sends
a method that receives files
private void onSharedIntent() {
Intent receiverdIntent = getIntent();
String receivedAction = receiverdIntent.getAction();
String receivedType = receiverdIntent.getType();
if (receivedAction != null && receivedAction.equals(Intent.ACTION_SEND)) {
Uri receiveUri = (Uri) receiverdIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if (receiveUri != null) {
//do your stuff
Uri fileUri = receiveUri;// save to your own Uri object
File file= new File(fileUri.getPath());
sendFile(file);
}
} else if (receivedAction != null && receivedAction.equals(Intent.ACTION_MAIN)) {
Log.v(TAG, "onSharedIntent: nothing shared");
}
}
FileNotFoundException: /-1/1/file:/data/user/0/com.google.android.apps.photos/cache/share-cache/media.tmp?filename=australia-lamenting-light-lake-view-landscapce%20(1).jpg/ORIGINAL/NONE/512356494: open failed: ENOENT (No such file or directory)
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", file.getName(),
RequestBody.create(MEDIA_TYPE_PNG, file))
.build();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question