How to share text from android app to facebook? - java

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"));

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 to share MP3 file + text in Android?

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!

Debugging an Android intent problem (no specific receivers)

I have a problem that I want in my application to have a specific email receiver whenever the user press the email button it shows to him/her a fixed receiver. How can I do this?
public void google(View v){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "");
Intent shareIntent = Intent.createChooser(emailIntent,"");
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(shareIntent);
}
this is the code
this is the image of email
Use this code hope it will help
Intent Email = new Intent(Intent.ACTION_SEND);
String[] recipents ={"your_recepient_email"};
Email.putExtra(Intent.EXTRA_EMAIL,recipents);
Email.setType("text/html")
Email.setPackage("com.google.android.gm");
startActivity(Intent.createChooser(Email, "Send mail"));
If you want subject and content use the code like how you added the lines for subject.

No Apps can perform this action android

I'm trying to make this program that when the user clicks a button, a message is sent to a whatsapp number
Here is the code in the onClick method
Uri uri = Uri.parse("smsto:" + "xxxxxxxxxx"); //xxx.. is the mobile number
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, "Check");
i.setType("text/plain");
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
It shows that there are no apps that can perform this action. Why?
I removed
i.setType("text/plain");
And it works. But the text "Check" is not sent. How to do that if this is not the way.
Your format is slightly different from the example given on the WhatsApp FAQ, so I would modify to match.
From this page:
Like most social apps on Android, WhatsApp listens to intents to share media and text. Simply create an intent to share text, for example, and WhatsApp will be displayed by the system picker:
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
However, if you prefer to share directly to WhatsApp and bypass the system picker, you can do so by using setPackage in your intent:
sendIntent.setPackage("com.whatsapp");
This would simply be set right before you call startActivity(sendIntent);
Try this code to send ON whatsapp
public void SendWhatsapp(View view) {
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}

How to share picture or text from fragment to Facebook using android studio?

I try to share picture from a fragment in android studio to facebook
..... the application has many of fragments so if i press on "share" the picture in this fragment will share on my Facebook and so on for the rest.
I used Intent to share text but this not work :
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, desc.getText().toString());
startActivity(Intent.createChooser(intent, "Share with"));
share(desc.getText().toString());
Thanks
try this reference:
: http://simpledeveloper.com/how-to-share-an-image-on-facebook-in-android/
hope it will help you.if it is working accept my answer
You can try this with the use of facebook sdk.
private void shareFacebook(){
if (!ShareDialog.canShow(ShareLinkContent.class)) return;
ShareDialog dialog = new ShareDialog(this);
ShareLinkContent.Builder builder = new ShareLinkContent.Builder();
builder.setContentUrl(Uri.parse("FileSharingUrl"));
builder.setImageUrl(Uri.parse("image url"));
if (mSharePhotoosUrl) {
builder.setContentDescription("body description");
}
if (mShareCreator) {
builder.setContentTitle("title if any");
}
dialog.show(getActivity(), builder.build());
}
}

Categories