Intent for Chat applications - android

I want to send text from my app, have copied text to clipboard using clipboard manager . Now what I want to do is to create an Intent chooser which only display chat apps like Hike, WhatsApp, sms or any other similar app.
How to do it?

Just use a SEND intent.
Similar to:
String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.share_using)));
It'll show all apps, including email. WhatsApp etc. will ignore the subject, while an MMS or email will use it.

Related

In an application, do we have a way to customise the share intent object so that we add additional text in Email chooser and not in sms chooser?

In our Android application, I am using Intent to share a URL as text with apps like Email apps, SMS app. I want to add an additional text as a signature (which should be appended to the original text) only in case of choosing Email and not in case of choosing SMS. Please suggest, how I can use different text for Email and SMS? Here is the sample code I am using for simply sharing.
String shareBody = "Here is the share content body";
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share using"));

Android Intent.SEND with text and link to messenger won't work

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "SHARE BODY https://www.messenger.com");
startActivity(Intent.createChooser(sharingIntent, "HUO"));
This text will be shared correctly for other apps, but messenger will only share the URL. Why? How can I fix this?
This text will be shared correctly for other apps
Some apps might support that. Apps do not have to, as what you are doing (using both EXTRA_TEXT and EXTRA_STREAM) is outside the scope of the ACTION_SEND contract. You are supposed to use either EXTRA_TEXT or EXTRA_STREAM, not both.
How can I fix this?
Get rid of EXTRA_TEXT, or get rid of EXTRA_STREAM, or live with random results from apps with your existing Intent structure.

How to make app picker for sharing text permanent in Android?

I'm trying to make refer and earn activity in my appSo I want to permanently display a few apps like whatsapp, etc for the user to click on them and share directly.I'm using Intent to share the referral code but it pops up the apps list when the user clicks share.The code I'm using is,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, "This is a message");
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Share via"));
How can I make the app chooser permanent for a few apps?
The app chooser is not intended to be displayed permanently. Therefore you will have to create simple buttons or icons and create an intent that refers to the desired app directly, by setting the package of the intent.
E.g. to share sth with WhatsApp use sth like this:
Intent sendIntent = new Intent();
// here comes the magic
sendIntent.setPackage("com.whatsapp");
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Depending on the type of content you want to share and the apps you want to share with, it makes sense to reuse the code to create the intent and just set the respective package and eventually some additional parameters.
You will need package name of app and a Intent.
change ACTION_VIEW to ACTION_SENDTO
set the Uri as you did set the
package to whatsapp
Intent i = new Intent(Intent.ACTION_SENDTO,
Uri.parse("content://com.android.contacts/data/" + c.getString(0)));
i.setType("text/plain");
i.setPackage("com.whatsapp"); // so that only Whatsapp reacts and not the chooser
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "I'm the body.");
startActivity(i);
You can refer this link for More:
Send text to specific contact (whatsapp)
Sending message through WhatsApp
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, "your text content");
startActivity(intent)
I am facing same problem for share tamil font content in Whatsapp. I found the solution, this setType("*/*") share full content.

Forward to Viber with both number and text

does anybody know how to forward a text from my application to a specified number in Viber? Is it possible?
I have tried these two ways:
Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
sendIntent.setData(Uri.parse("smsto:00000000000"));
sendIntent.putExtra("sms_body", "text");
startActivity(sendIntent);
This one is forwarding to desired number correctly, but not passes the text.
and
String S1="test message";
Uri sms_uri = Uri.parse("smsto:00000000000");
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND, sms_uri);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, S1);
//sharingIntent.putExtra(android.content.Intent.EXTRA_PHONE_NUMBER, "00000000000");
startActivity(Intent.createChooser(sharingIntent, "share using"));
The above code is forwarding the text to viber but needs to select a number or contact to send the text.
I have tried almost any combinations of these two methods but could not achieve the goal.
I'm stuck with this for months, Any help will be appreciated.

Facebook share can't get the text

I want to make tweet/share buttons for gamers. They will make them able to write some tweets or share the gained score in the wall.
I found this code:
String shareBody = "Share text";
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject Here");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Test"));
This code is quite good.
For the Twitter app, the text is sent correctly. ("Share text")
But it doesn't work for the facebook app.
Where is the error?
Thanks in advance!
You have no error - it's simply impossible.
Facebook is limiting the "share via intent" to display only the hyperlinks if exists. you can't display any regular text.
The only way to do that is to make a full facebook connect (Facebook's Android SDK) and ask post-to-wall permissions from user.

Categories

Resources