Input and output path in Android - android

I am using FFMPEG to make a video editor. I stuck when selecting a folder:
1/ I will show "File Manager" to user. They can choose a folder then return a path. How can choose a folder and get its path. For example: /sdcard/videokit/.
Here is my code, I must choose a mp4 file (not a folder I want).
public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/sdcard/");
intent.setDataAndType(uri, "folder|video/mp4");
startActivityForResult(Intent.createChooser(intent, "Select Folder"),PICK_VIDEO_OUTPUT_REQUEST);
}
Thank you in advance!

No, you cannot use Intent to choose folder in Android. You need a dialog of your own. Luckily, there are plenty ready to use code samples available, e.g. How to select folder in android?.

Related

Opening image with Intent through absolute file path

I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */

Select folder dialog on android?

Is there some 'select folder dialog' on android SDK ?
I google it and i did not find anything.
I mean that i looking for dialog that will popup and give me the option to select a path of folder ( like select file dialog ... but the return argument will be full path of a folder )
Its hard to believe that on this marvelous sdk there is no way to select full folder path.
Any help please ..
thanks.
public void performFileSearch() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
startActivityForResult(intent, READ_REQUEST_CODE);
}
Or If you using samsung phone, You can call Intent.
//Samsung Device
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
providers/document-provider
This link will be help for you
you can use this library to do the same:
https://github.com/passy/Android-DirectoryChooser

Get file location path in Android

My problem is that I cannot get a full path of a file in Android. I search on Google and find out this code which has a result nearly what I want:
public void openFolder()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+ "/sdcard/");
intent.setDataAndType(uri, "image/png");
startActivity(Intent.createChooser(intent, "Open folder"));
}
I choose file from "File Manager". After I access some folders and finally reach my file in "File Manager", the "File Manager" closes and no path is saved.
What should I do in order to save the path and file name? Ex: "/sdcard/Download/frame1.png".
Thank you in advance!
I believe you will need to implement onActivityResult as described in an example below.
Example: http://steveliles.github.io/returning_a_result_from_an_android_activity.html
First you can assign a File object to your file as fileA.Then the file path should be path = fileA.getAbsolutePath();
You can store this String in your clipBoard using ClipboardManager.

How to open specified directory

I have application which generate PDF, then I put in folder A, how can I open and exploring all files in folder A when clicked button (showing new Intent)? I wish that my preview like when click My Files >> Folder A >> [files].
Doe this code help?
original source
String folderPath = Environnement.getExternalStorageDirectory()+"/A";
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
Uri myUri = URI.parse(folderPath);
intent.setType("file/*");
startActivity(intent);
This function will get you the sdcard root :
getExternalStoragePublicDirectory()
After getting the root you can create or open a folder.
to create a folder use
mkdir()
or
mkdirs()
functions.
to get all the files from that folder you can use File object.
Here is the example source code for file explorer in android :
https://github.com/mburman/Android-File-Explore
Its very straightforward forward code

View folder contents in Android using default explorer

I want to programatically launch a default file explorer to show me the contents of a folder.
I'm using this code, but it crashes:
Uri startDir = Uri.fromFile(new File("/sdcard/DCIM/Camera"));
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(startDir);
startActivity(intent);
LogCat shows "No Activity found to handle the Intent"...
What's my best option to do this? I want the user to see the contents of the folder and be able to click the files (e.g. click a video and launch it with default player, click a PDF and open it etc).
Unfortunately there seem to be no standard way to do this, I was searching for the exact same thing before and couldn't find out any solution. There are 2 alternative methods that might work for you:
1) Use a general intent and let the user pick his/her file manager
This is safe and easy but a little far from what we really want
Uri startDir = Uri.fromFile(new File(Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/DCIM/Camera"));
Intent intent = new Intent();
intent.setData(startDir);
intent.setType("*/*");
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
Don't use intent.setType("file/*");, it's not a standard MIME type.
2) Use Specific Intents that the famous file managers provide The well known file managers have their own custom intent filters that accept a directory path which allows simple browsing. Some of them are here: OI file manager, ES Explorer
Maybe you could check if the user have these specific file managers installed and then use this solution, else fallback to general intent.
For now these are the only two options you have. I will update this post if I find out any better solution.
Although I could not get the OI file manager to go to a specific directory, the following opens up the OI File Manager directly and goes to the last directory it was in.
Intent importFileIntent = new Intent();
importFileIntent.setType( "file/*" );
// Does nothing.
// Uri startingDir = Uri.fromFile( new File(
// Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera"));
// importFileIntent.setData( startingDirectory );
importFileIntent.setAction( Intent.ACTION_GET_CONTENT );
// Ensure that there's an activity to handle the intent.
if (importFileIntent.resolveActivity(getPackageManager()) == null) return;
startActivityForResult(importFileIntent, REQUEST_FILE_IMPORT);
If anybody has further success, I would love to hear it.

Categories

Resources