I've been dealing with a problem regarding the sharing of images in an Android app. I've been told it's easier to save the image I want to share in the content provider. I've done that like this: ( don't know if i am doing it right )
File auxFile = new File(getContext().getFilesDir(), imgName);
if (!auxFile.exists()){
FileOutputStream fos = new FileOutputStream(auxFile);
fos.write(bytesDecrypted);
fos.flush();
fos.close();
}
Once that is done I try to share the image through a chooser intent like this:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/jpeg");
Log.v("CachedProvider",CachedFileProvider.AUTHORITY);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("content://" + CachedFileProvider.AUTHORITY + File.separator + imgName));
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent,"share"));
In the app I have implemented a method that can receive Images from other apps sharing it ( that part actually work ) so I decided to test my sharing "button" with my own app but it actually don't work.
For the moment I have not set any special provider on my manifest as I don't know if that is necessary.
If further information is needed please feel free to ask.
Thanks you all very much in advance!
Edit:
When I click the "button" a "chooser" between the diferent apps that accept images is beeing displayed. Once I choose the app that I want to share the image with I get no responce.
Related
The question is, how do I send a large image (example 720 * 8549) to the WhatsApp without compression and loss of quality.
Is it possible to do this?
Below is the code to send the image that I use:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
File photoFile = new File(imageFile.getParent(), imageFile.getName());
Uri photoURI = FileProvider.getUriForFile(getBaseContext(), getApplicationContext().getPackageName(),
photoFile);
shareIntent.putExtra(Intent.EXTRA_STREAM,photoURI);
shareIntent.setType("image/*");
startActivity(Intent.createChooser(shareIntent, getBaseContext().getString(R.string.photo_share)));
So I send a compressed and unreadable image.
Maybe someone came across a similar.
Good luck to all!
This is not possible because WhatsApp always reduces the size. Google Photos also tried this but if you choose Original when sending over Google Photos the size is still shrinked in the end.
Why do you not take another app like Telegram? You have much more options there.
The easiest way would be to share a link to the original e.g. Google Photos or Dropbox.
I have an app with different sounds. I'd like to share a sound(audio) together with a text.
If I share only a sound it works:
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().toString() + "/audio.mp3"));
share.setType("audio/mp3");
startActivity(Intent.createChooser(share, "Share via..."));
Now I tried to add a text:
share.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStorageDirectory().toString() + "/audio.mp3"));
share.setType("audio/mp3");
sharetext.putExtra(Intent.EXTRA_TEXT,"This should be under the audio file after sharing");
startActivity(Intent.createChooser(share, "Share via..."));
But still only the audio get shared.
How does it works?
And if this isn't possible is there an other way to do this?
Thank you very much! :)
It really depends on what app you end up choosing when you're using the chooser to share the audio file as it's up to the chosen application to decide whether or not to use the supplied text set by EXTRA_TEXT. In short, you really don't have much control over this.
I recently noticed that when sharing an animated .gif that I generate from my app, the official Twitter app will only share it as a static image.
Previously, I thought everything was working because when I shared the same type of animated .gif with an unofficial Twitter app (Tweetcaster), it properly shared it as an animated .gif.
The thing I'm questioning is whether this is an issue on my end or with the official Twitter app? I ask this because when sharing an animated .gif from the Android Gallery with the official Twitter app, it is also posted as a static .gif.
Here's the code in question:
public void shareGif(String path)
{
File file = new File(path);
Uri uri = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/gif");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
intent.putExtra(Intent.EXTRA_SUBJECT, "subject");
intent.putExtra(Intent.EXTRA_TEXT, "text");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent, "Choose a sharing option"));
}
I was having the same issue as you. I was loading URIs from the drawables and for whatever it was not animating.
I fixed my problem by implementing a custom file provider and loaded GIFs from the assets folder.
Also it was very important to add this flag intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
Twitter supports looping GIFs. If your animated GIF doesn’t loop and plays a single time, it will display as a static image.
I am using the easy camera intent for taking simple pictures in Android as follows:
Uri outputFileUri = Uri.fromFile( photo );
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
camera.putExtra( MediaStore.EXTRA_OUTPUT, outputFileUri );
this.startActivityForResult(camera, CAMERA_RESULT);
The problem is: The file is saved twice
Once when the picture is actually taken (then it is saved to the gallery directory)
Once when the user "accepts" the picture (then it is saved to outputFileUri)
Although I really cant imagine this fact I already read about that the creating of those duplicate files cannot be avoided. But if not, is there a possibility to get the path of the picture in the gallery directory to delete it by my app?
Just to let you guys know, I did some research and it is actually not a good idea to solve it like this - unfortunately.
Nevertheless you can do a very easy SurfaceView-Camera-Activity which will only save the data you are telling it to.
Hi I'm working on an app where I need to list all types of applications able to open a file. If the file were an image I would do something like this normally to show all applications capable of viewing the image.
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file), "image/*");
context.startActivity(intent);
However say I have an unknown file how could I list all applications able to view a file so the user can select the appropriate application to open the file in my application.
I also need the titles listed in an arraylist if possible so I can list them in a listview.
Thank you for any help with getting a list of applications capable of viewing a file
===================================
Edit
Alright well something easier how can i get the applications from the above intent into an arraylist i could just do image/* audio/* etc and add them all to a list and then list them in a listview and that would solve my problem
As far as i know there is no API in android that links files to a program like in windows. Your best choose I'm afraid is to build a database of known file types and program/android app linked to them.
Okay well i figured my problem out what i was looking for was
Intent audioIntent = new Intent(android.content.Intent.ACTION_VIEW);
audioIntent.setDataAndType(Uri.fromFile(Opener.file), "audio/*");
List<ResolveInfo> audio = packageManager.queryIntentActivities(audioIntent, 0);
for (ResolveInfo info : audio){
String label = info.loadLabel(packageManager).toString();
Drawable icon = info.loadIcon(packageManager);
String packageName = info.activityInfo.packageName;
String name = info.activityInfo.name;
iconlabel.add(a.new HolderObject(label, icon, audioIntent, "audio/*", packageName, name));
}
But the main thing in the code above is the queryIntentActivities method that was what solved my issue allowing me to add those apps to a list
This may help you to list the application that are capable of opening a particular file.
// extension : The file extension (.pdf, .docx)
String extension = filePath.substring(filePath.lastIndexOf(".") + 1);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
if (null == mimeType) {
// Need to set the mimetype for files whose mimetype is not understood by android MimeTypeMap.
mimeType = "";
}
File file = new File(filePath);
Uri data = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(data, mimeType);
context.startActivity(Intent.createChooser(intent, "Complete action using"));