Share audio and text together - java

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.

Related

Share mp3 file from Storage to specific whatsapp user

private void share(Uri uri){
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("audio/*");
waIntent.putExtra("jid", get_DATA.getSelectedPhonewdcountrycode() + "#s.whatsapp.net"); //phone number without "+" prefix
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(waIntent, "Share with"));
}
I have tried many solution but every solutio takes me to whatsapp contact list to chose a contact, i want the file to be send directly to users inbox
BTW it does take me to the targeted contact after a few second delay but it toast a message File is not supported
There is no foreseeable way to upload it directly from a file to a user (unlike on laptops), unless you extend the file path to reach a particular contact e.g
com.whatsapp.jeremy
This however might still not help as WhatsApp chats are end to end encrypted, not direct, so you might have to go through some of the database files like db.crypt to find the right path to each individual.
Try seeing how these pan out for you

Send image as document to whatsapp programmatically

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.

Trouble sharing Images

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.

Why does the Twitter app not share animated gifs?

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.

Android Camera Intent saving file twice / how to avoid

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.

Categories