How to open specified directory - android

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

Related

share a file created with DocumentFile.createFile

I have an app that downloads files to folder selected by the user.
I get access to the folder using :
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION|Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
startActivityForResult(intent,REQUEST_PICK_FOLDER_TO_DOWNLOAD);
create the downloaded file with
DocumentFile newFile = destDir.createFile(mime, file.getFileName());
I need to share the file. For example if this is a text file, pdf or word doc user can open it in the appropriate app.
File URI seems pretty strange:
"content://com.android.externalstorage.documents/tree/primary%3Amy_logs/document/primary%3Amy_logs%2Fford-f-150-raptor-2019-491746%20(1).jpg"
But it is a file created with createFile and I am able to write the contents.
I am not sure FileProvider can help as the dest folder is any folder on the device.
I am not sure is there anyway to share that URI with any other app?
Thank you very much!
V

Unable to share image in android

I am new in android Java.
I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
cordova.getActivity().startActivityForResult(share, 0);
Above code is not working, it showing like this ...
is think i cant get Exact image file location.
My file location
I tried bellow code also, But not work,
String imagePath = Environment.getExternalStorageDirectory()
+ "/assets/www/sharethis.png";
Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file

Unable sharing image in android

I am new in android Java. I am trying to share an image in android application using Phonegap. I get new class "Share" as CordovaPlugin, code is follow...
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/*");
Uri uri = Uri.parse("file:///android_asset/www/sharethis.png");
share.putExtra(Intent.EXTRA_STREAM, uri);
Above code is not working, it showing like this ...
is think i cant get Exact image file location. My file location
I tried bellow code also, But not work,
String imagePath = Environment.getExternalStorageDirectory()
+ "/assets/www/sharethis.png";
Please Help
Android asset folder is private to your app so you can't share files from there directly. You need to copy the file from assets to a public directory in the filesystem and then send the share intent pointing to the public file. Have a look here

Input and output path in 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?.

Opening Image File gives error in Android

I am trying to open a jpg image file in gallery. This gives a error. I am using the code below
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("/mnt/sdcard/image123.jpg"),"image/jpeg");
startActivityForResult(intent, 900);
This gives a option to open file in gallery. I select Gallery from the list. But it does not open up. I use ASTRO file manager and open the same image file. It opens up fine now. Please let me know if something is wrong.
Where do you got /mnt/sdcard. Try Environment.getExternalStorageDirectory().getAbsolutePath() instead.
Specified Image Path? You can't. Please Refer My Question as How to access different File Manager specific path. Refer this link and then you got a answer.

Categories

Resources