How to open gallery in specified folder using intent - java

Can you help me how to open gallery in specified folder using intent?
It only opening gallery from specified folder like this (screenshot below).
However, it is not returning any value or activity.
I've try a lot of methods, but none open the specified gallery folder
I tried
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
This works, but only opening gallery, not in specified folder
another one
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/CameraExample/");
intent.setDataAndType(uri, "*/*");
startActivity(Intent.createChooser(intent, "Open folder"));
this will open recent file, but it's not just viewing gallery, it choose a file, and return it.
Intent intent = new Intent();
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/CameraExample/");
intent.setDataAndType(uri, "*/*");
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
and it only shows a whitescreen. Is it possible to open gallery in specified folder? It would open like this if possible:

is it possible to open gallery in specified folder?
No, sorry.

The gallery selection was not designed to be opened from any location like that. Supported locations:
Album location(
/sdcard/dcim)

Related

Open file from specific folder with Intent.ACTION_OPEN_DOCUMENT

I would like to open the file picker at a specific path. The user should be able to pick any file on the phone, but the SAF should show a specific folder first. I tried the following but it always opens the downloads folder. Thanks!
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
Uri uri = Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath());
intent.setDataAndType(uri,"image/*");
startActivityForResult(intent, 1);
you need to use the extra EXTRA_INITIAL_URI

How to share image (File Path) with content using share Intent in all devices

I am downloading image and taking it filepath to share but it is not working on all platforms except whatsapp. While it is showing can't upload image on insta and file not attached on gmail.
`private void genericShare(Activity activity) {
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, downloadedFilesPath);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
shareIntent.setType("image/jpeg");
shareIntent.putExtra(Intent.EXTRA_TEXT,getClipBoardText(activity));
activity.startActivity(Intent.createChooser(shareIntent,
activity.getResources().getText(R.string.share_using)));
}`
Check the following demo app code, after clone it just change the hardcoded file path.
https://github.com/nikkulshrestha/imageShare

Is there way to share *.json file via Intent or something else?

In my app I need to share *.json file to other app (messenger, google disk, etc). How can I do this via Intent or something else?
But when I trying to do this via Intent, I have some problems.
override fun shareBackupData(path: String) {
val uri = Uri.parse(path)
val shareIntent = Intent()
shareIntent.action = Intent.ACTION_SEND
shareIntent.putExtra(Intent.EXTRA_STREAM, uri)
shareIntent.type = "*/*"
startActivity(Intent.createChooser(shareIntent, "Choose"))
}
When I run this code, I choose app to share and then I see toast "unsupported attachment"
I had similar problems with this and I found this article where it recommends us to use FileProvider.
What it does is :
FileProvider is a special subclass of ContentProvider that facilitates secure sharing of files associated with an app by creating a content:// Uri for a file instead of a file:/// Uri.
I recommend you to take a look to the article and also if you want code, take a look at this Stackoverflow post
i think you can use the file as ExtrtaStream the following code is sharing image file you can change it to your json file
final Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/jpg");
final File photoFile = new File(getFilesDir(), "foo.jpg");//change it with your file
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(photoFile));
startActivity(Intent.createChooser(shareIntent, "Share image using"));

Share image from Android App [duplicate]

This question already has answers here:
photo share intent in android
(3 answers)
Closed 6 years ago.
I'm having troubles sharing an image from my app to other apps.
The problem is when I share the image, it doesn't include the extension and other apps like messenger, whatsapp or gmail doesn't recognise them.
My code is:
Intent intent = new Intent(Intent.ACTION_SEND);
String path = "android.resource://com.xxxx.xxxxxxx/drawable/image";
Uri screenshotUri = Uri.parse(path);
intent.putExtra(Intent.EXTRA_TEXT, "Hello world!");
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share:"));
I'm having the same problem sharing audio:
Intent share = new Intent();
share.setAction(Intent.ACTION_SEND);
String sharePath = "android.resource://com.xxx.xxxxx/raw/" + sound;
Uri uri = Uri.parse(sharePath);
share.putExtra(Intent.EXTRA_STREAM, uri);
share.setType("audio/mp3");
Intent i = Intent.createChooser(share, "Share Sound File");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
baseContext.startActivity(i);
I already checked the official documentation and still having problems: https://developer.android.com/training/sharing/send.html
Thanks for help or any hints!
You have to write the image or audio file to the sdcard or ExternalStorege before sharing. The reason is other apps don't have the access to the files which are in your app's private memory. So to share the image or any other file from your app, you must make it available for other apps to read.

How do I use the PDFViewer.jar library in android?

I am trying to use the PDFViewer.jar library to read pdf into my application android pdf reader.
I wonder how to use to read pdf form the resources in asset folder.
it required to "PATH TO PDF GOES HERE"
Intent intent = new Intent(this, YourPdfViewerActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "PATH TO PDF GOES HERE");
startActivity(intent);`
It's explaining quite good and works for me.
http://upadhyayjiteshandroid.blogspot.com/2013/03/android-pdf-viewer-application.html?showComment=1397014240605#c4120910608580621305
Yes path is required
Intent intent = new Intent(this, YourPdfViewerActivity.class);
intent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "file:///android_asset/pdf_name.pdf");
startActivity(intent);

Categories