Unable to share image in android - 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

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

Create a share intent that also allows to save a document on Android

Is there any way to create a share intent that gives the user the option to save the file somewhere in the device? Like an intent with ACTION_CREATE_DOCUMENT.
My situation is the following: I have a file that is NOT visible to the user, saved in the app's documents folder via getExternalFilesDir, and I want to allow the user to either share that file, or save it directly in an accessible folder (it would be nice to suggest the user a path, like the file explorer opening directly in the public Download folder, but it is not needed). All of this should be wrapped inside the share intent, as I am only allowed to edit that as of now.
The code looks something like this:
String packageName = Utils.currentContext.getApplicationContext().getPackageName();
Uri uri = FileProvider.getUriForFile(Utils.currentContext, packageName + ".provider", file);
Intent intentShareFile = new Intent(Intent.ACTION_SEND);
intentShareFile.setType(type);
intentShareFile.putExtra(Intent.EXTRA_STREAM, uri);
intentShareFile.putExtra(Intent.EXTRA_SUBJECT, text);
intentShareFile.putExtra(Intent.EXTRA_TEXT, text);
intentShareFile.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Intent shareIntent = Intent.createChooser(intentShareFile, "Sharing file");
Utils.currentActivity.startActivity(shareIntent);
I tried working with putExtra as well as addCategory with no success.

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 */

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

Android Open PDF Intent

I need to open a PDF. I know the procedure, this is my code:
string file_path = _path + url.Substring (5);
if (System.IO.File.Exists(file_path)) {
Android.Net.Uri pdfFile = Android.Net.Uri.FromFile (new Java.IO.File (file_path));
Intent pdfIntent = new Intent (Intent.ActionView);
pdfIntent.SetDataAndType (pdfFile, "application/pdf");
pdfIntent.SetFlags (ActivityFlags.NoHistory);
_parent.StartActivity (pdfIntent);
return true;
}
I'm using Xamarin, and the path exists because i check it as you can see.
The app opens Adobe reader, but when it starts an error message shows up saying (File not found). So, my file is in
/data/data/com.myapp/files/.hide/contents/file_test.pdf
Are there some permission to set? I really don't understand why it can't open my file!
The folder /data/data/com.myapp is the private folder of your application. So no other application can access to the content of this folder (in this case Adobe reader).
Instead try to put your pdf into a SDCard folder.

Categories

Resources