How to share MP3 file + text in Android? - java

I have tried to make a code for sharing an MP3 file and text at once on Button click, but in reality when I click the share button and choose for example WhatsApp I can only share the MP3 file but not the text with the MP3 at once. Here is the code that I am using to share this both files:
btn_share.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
String sharePath = OUTPUT_PATH+"temp/output/out.mp3";
Uri uri = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("*/*");
share.putExtra(Intent.EXTRA_STREAM, uri);
share.putExtra(Intent.EXTRA_TEXT, "Get more info about our band");
startActivity(Intent.createChooser(share, "Share your sound"));
}
});
Is it not possible or is WhatsApp just blocking such actions? Do you know a solution to fix it? Thanks in advance for helping me!

Related

How to share image from recyclerView arraylist?

I am trying to share an images from arraylist,when I click on share button app list appears to share but when I select an app to share,it shows null in another app.
please help me to find out the solution :(
here is my recycler onBindViewHolder code.
holder.send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
final String image_path = fileslist.get(position).getUri().toString();
File share = new File(image_path);
Uri uri = Uri.fromFile(share);
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("image/");
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
context.startActivity(Intent.createChooser(shareIntent, "Share to....."));
}
});
and here how my app is sharing

How can share file to whatsapp?

I used the codes below. When I press the button, whatsapp opens, when I select the person I will share and press on it, the audio file is not sent and the text "sharing failed please try again" appears? Is there a problem with my codes, do not I understand the file format?
there is my raw folder
enter image description here
paylas.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri catURI;
catURI = Uri.parse("android.resource://your.app.package/" + R.raw.helikopter);
Intent videoshare = new Intent(Intent.ACTION_SEND);
videoshare.setType("*/*");
videoshare.setPackage("com.whatsapp");
videoshare.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
videoshare.putExtra(Intent.EXTRA_STREAM,catURI);
startActivity(videoshare);
}
});
I saw you want to send a .mp3 file. So you need the setType("audio/*")
I made an example with a ringtone. That's how you can send music:
paylas.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String sharePath = Environment.getExternalStorageDirectory().getPath()
+ "/Soundboard/Ringtones/custom_ringtone.ogg";
Uri catURI = Uri.parse(sharePath);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("audio/*");
share.putExtra(Intent.EXTRA_STREAM, catURI);
startActivity(Intent.createChooser(share, "Share Sound File"));
}
});
Make sure you have internet and External Storage granted in your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Hope your question is answered now. Give it a shot, but I bet it works :)

GIF is getting shared as an image not animated - Android Java

I am trying to share an GIF programmatically, but it is getting shared as an image (not animated)
Code Snippet:
Intent shareIntent = new Intent();
shareIntent.setType("image/gif");//image/gif
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(myList.get(item)));
startActivity(Intent.createChooser(shareIntent,"Share gif"));
You are trying to share to which apps?
Some whatsapp builds don't support gif feature.
You can check this question here with some additional information: How to share GIF image in Whatsapp programmatically in Android?
There is this comment:
"This solution doesn't work with whatsapp but does work with all the other apps I specified above (namely Hangouts, Android Messages, Facebook Messenger)"
He is referring to this answer:
private void ShareGif() {
// replace the path and file name with your gif image path and name
String baseDir = Environment.getExternalStorageDirectory().getAbsolutePath();
String fileName = "temporary_file.gif";
File sharingGifFile = new File(baseDir, fileName);
Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("image/gif");
Uri uri = Uri.fromFile(sharingGifFile);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "Share image"));
}
/*
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setPackage("com.whatsapp");
shareIntent.putExtra(Intent.EXTRA_TEXT,title + "\n\nLink : " + link );
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(sharePath));
shareIntent.setType("image/*");
startActivity(shareIntent);
*/
Hope it helps.

Open story page of instagram to share image or video

I want to share my image into instagram story. Now I can open istagram easily like this , but this code show me the page that we share photo.
I dont want this one, I want to open instagram story page just.
Here with this code:
try {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
File media = new File(path);
Uri screenshotUri = Uri.fromFile(media);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
sharingIntent.setPackage("com.instagram.android");
startActivity(sharingIntent);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(SavedActivity.this, "برنامه اینستاگرام یافت نشد.", Toast.LENGTH_LONG).show();
}
Is it possible to share directly into story of instagram?
This is not possible (not to mention bad practice).
You can only dictate which application(s) can handle your intent, not what they do with that intent once it is received.
It is also not good practice to hardcode the application package you want to send to within your codebase (i.e. "com.instagram.android"). The Android documentation as well as the Instagram developers documentation recommends that you use the standard "chooser" pattern to share photos. In which case, the user will decide which app to share the photo with.
Intent share = new Intent(Intent.ACTION_SEND);
share.setType(type);
File media = new File(mediaPath);
Uri uri = Uri.fromFile(media);
share.putExtra(Intent.EXTRA_STREAM, uri);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(share, "Share to"));
} else {
Toast.makeText(this, "No application to share with", Toast.LENGTH_SHORT).show();
}
Unless this is a personal project (it will not make it to the Google Play Store), I suggest you stick to the above pattern.
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(String.valueOf(dest));
sharingIntent.setType("video/*");
sharingIntent.setPackage("com.instagram.android");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share Video "));
I hope it helps someone .

How to share text from android app to facebook?

I try to implement share button in my android app to share in facebook
The code:
facebook.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_SUBJECT,desc.getText().toString());
startActivity(Intent.createChooser(share, "Share description using"));
}
});
The problem is, in the post dialog of the facebook not display the text which i need to share from my app which it is (desc.getText().toString()) . There empty message !! why the text didn't appear !!!
Thanks in advance
Try with this. Hope it help
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Share Something");
startActivity(Intent.createChooser(intent, "Share with"));

Categories