I have a requirement of sending a url(myapp://app.myapp.com/data)with custom scheme through WhatsApp.But in WhatsApp its not showing custom scheme(myapp://) as link. Only app.myapp.com/data is showing as link.
I have tried below code:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT,"Please check this link: "+Html.fromHtml("myapp://app.myapp.com/data"));
intent.setType("text/plain");
startActivity(Intent.createChooser(intent, "Select Chooser to send friend"));
Is it possible to send link with custom scheme on WhatsApp in android platform?
try this code:
Whatsappbutton.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi") #Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
Tracker t = ((Analytics) getActivity().getApplication())
.getTracker(TrackerName.APP_TRACKER);
t.send(new HitBuilders.EventBuilder()
.setCategory(getString(R.string.ic_Category))
.setAction(getString(R.string.ic_action))
.setLabel(getString(R.string.ic_labelwhatsapp)).build());
} catch (Exception e) {
Toast.makeText(getActivity().getApplicationContext(),
"Error" + e.getMessage(), 1).show();
}
Toast.makeText(getActivity(), R.string.invite_friends_toast_after_share, Toast.LENGTH_LONG).show();
final String shareBody = getResources().getString(R.string.invite_friends_market_url);
try {
Intent shareToWhatsApp = new Intent(Intent.ACTION_SEND);
shareToWhatsApp.setType("text/plain");
shareToWhatsApp.putExtra(android.content.Intent.EXTRA_TEXT,
shareBody);
shareToWhatsApp.setClassName("com.whatsapp",
"com.whatsapp.ContactPicker");
startActivity(shareToWhatsApp);
} catch (Exception e) {
Intent shareGeneric = new Intent(Intent.ACTION_SEND);
shareGeneric.setType("text/plain");
shareGeneric.putExtra(android.content.Intent.EXTRA_TEXT,
shareBody);
startActivity(Intent.createChooser(shareGeneric,
getResources().getString(R.string.invite_friends_share_chooser)));
}
}
});
Related
I am adding share feature in the app. Below is my code:
public static void shareData(String title, String message, Uri imageUri, Activity activity) {
try {
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TITLE, title);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, message);
if (imageUri != null) {
Logger.errorMessage(ShareUtil.class.getSimpleName(), "share if");
sendIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
sendIntent.setType("image/*");
} else {
Logger.errorMessage(ShareUtil.class.getSimpleName(), "share else");
sendIntent.setType("text/plain");
}
activity.startActivity(Intent.createChooser(sendIntent, "Share using"));
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(activity, "No App found to share", Toast.LENGTH_LONG).show();
}
}
This is showing the list of apps, but when I select any app, the title and message is not sent. I am not getting what I am doing wrong.
Intent.EXTRA_SUBJECT is mainly used in email. Try replacing it with Intent.EXTRA_TEXT. This works in most apps.
Using this code only open particulat number's chat but Text is not share.How can I do this?
public class MainActivity extends AppCompatActivity {
Button Wa;
String id = "+919000000000";
EditText txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (EditText)findViewById(R.id.editText);
Wa = (Button)findViewById(R.id.btn_whatsapp);
Wa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Uri uri = Uri.parse("smsto:" + id);
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
String text = "testing message";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, text));
} else {
Toast.makeText(getApplicationContext(), "WhatsApp not found", Toast.LENGTH_SHORT)
.show();
}
}
});
}
Since you trying to achieve it as "smsto:", "text/plain" as type will help you. Try Extra as "sms_body" if it won't help.
Uri uri = Uri.parse("smsto:" + id);
Intent waIntent = new Intent(Intent.ACTION_SENDTO,uri);
String text = "testing message";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.setType("text/plain");
//waIntent.putExtra(Intent.EXTRA_TEXT, text);
waIntent.putExtra("sms_body", text);
startActivity(Intent.createChooser(waIntent, text));
} else {
Toast.makeText(getApplicationContext(), "WhatsApp not found", Toast.LENGTH_SHORT)
.show();
}
Please go through this stackoverflow links
Sending message through WhatsApp
Send text to specific contact
It seems that WhatsApp still does't have supported this fetaure.
You can only open chat history for particular number using below code
try {
Uri mUri = Uri.parse("smsto:+98xxxxxxxx");
Intent mIntent = new Intent(Intent.ACTION_SENDTO, mUri);
mIntent.setPackage("com.whatsapp");
// mIntent.putExtra("sms_body", "My body");
mIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
startActivity(mIntent);
} catch (Exception e) {
// alert WhatsApp in not installed
}
Answer from Here
Earlier it wasn't possible but since the May '15 update. Checkout :
try{
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
String sendString = "some random string";
sendIntent.setPackage("com.whatsapp");
sendIntent.putExtra(Intent.EXTRA_TEXT, sendString);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
sendIntent.setType("image/*");
startActivity(sendIntent);
} catch (Exception e){
// some code
}
Here PackageInfo line is just to check if WhatsApp is installed. It throws Exception if not. You can just ignore that if you want to do a normal share (and setPackage also).
Also. It is important that the media you want to share has to be publicly available on local storage.
UPDATE
To send to a specific contact
Uri uri = Uri.parse("smsto:" + "<CONTACT_NUMBER>");
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
As Action Send To is now allowed.
Try something like this:
public class MainActivity extends AppCompatActivity {
Button Wa;
String id = "+919000000000";
EditText txt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txt = (EditText)findViewById(R.id.editText);
Wa = (Button)findViewById(R.id.btn_whatsapp);
Wa.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
PackageManager pm=getPackageManager();
try {
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
waIntent.setType("text/plain");
String text = "testing message";
PackageInfo info=pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
waIntent.setPackage("com.whatsapp");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, text));
}
catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not found", Toast.LENGTH_SHORT).show();
}
}
});
}
}
I wanna share text to whatsapp using ImageButton, but I don't know how to set the ImageButton to share the text.
Here is my code
ImageButton wasap = (ImageButton) findViewById(R.id.wasapKongsi);
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, R.id.hadisView + "/n" + R.id.textView);
try {
startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(hadis.this, "Whatsapp have not been installed.", Toast.LENGTH_LONG).show();
}
I hope anyone here can help me. Thanks
Just set ImageButton onClickListener
wasap.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
//your code here that you want to run
Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
whatsappIntent.setType("text/plain");
whatsappIntent.setPackage("com.whatsapp");
whatsappIntent.putExtra(Intent.EXTRA_TEXT, R.id.hadisView + "/n" + R.id.textView);
try {
startActivity(whatsappIntent);
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(hadis.this, "Whatsapp have not been installed.", Toast.LENGTH_LONG).show();
}
}
});
Is it possible to make an imageview link to the email app? Like when you click it the email app will open with a specific email address to send?
findViewById(R.id.imageview).setOnClickListener(new OnClickListener() {
public void onClick(View _) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.fromParts("mailto","abc#gmail.com", null));
startActivity(i);
}
}
img.setOnClickListener(
new OnClickListener(View v) {
String yourMail = "mail#example.com";
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{yourMail});
intent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
intent.putExtra(Intent.EXTRA_TEXT, "Your content");
try {
startActivity(intent, "Pick an email application...");
} catch(Exception e) {
Toast.makeText(YourMainActivity.this, "Have no email application!", Toast.LENGTH_SHORT).show();
}
}
);
This is how I am calling the SMS app:
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "The SMS text");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
How do I do the same for sending messages via twitter/Whatsapp/Facebook? What should I write in place of mms-sms? I found no documentation on such.
I can't also find any way of calling Facebook/Twitter directly, but you could always call android.content.Intent.ACTION_SEND and let the user choose the application.
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "Subject");
i.putExtra(Intent.EXTRA_TEXT, "Message body");
startActivity(Intent.createChooser(i, "Share dialog title"));
However, there might be a bug when using this to share through Facebook. For more information please see: Android Facebook Intent
public void onClickWhatsApp(View view) {
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "YOUR TEXT HERE";
waIntent.setPackage("com.whatsapp");
if (waIntent != null) {
waIntent.putExtra(Intent.EXTRA_TEXT, text);//
startActivity(Intent.createChooser(waIntent, "Share with"));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}} catch (NameNotFoundException e) {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
}
Intent i = new Intent(Intent.ACTION_SEND);
i.setPackage("com.whatsapp");
i.putExtra("chat",true);
i.setType("text/plain");
startActivity(i);
You can use the following snippets:
For WhatsApp:
public void onClickWhatsApp(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();
}
}
For Twitter:
void shareOnTwitter()
{
PackageManager pm=getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Insert Tweet Here";
#SuppressWarnings("unused")
PackageInfo info=pm.getPackageInfo("com.twitter.android", PackageManager.GET_META_DATA);
//Check if package exists or not. If not then code
//in catch block will be called
waIntent.setPackage("com.twitter.android");
waIntent.putExtra(Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (NameNotFoundException e) {
Toast.makeText(this, "Twitter not Installed", Toast.LENGTH_SHORT)
.show();
return ;
}
return ;
}