Is it Possible to send whatsapp from the number stored in database(SQLite)
SO Far I have tried sending a whatsapp from older post but its sending ony msgs or opening only contacts when i am combining both I am not getting any result
//This Will Open Specific Contact on Whatsapp
void openWhatsappContact() {
String number = "919033152265";
Uri uri = Uri.parse("smsto:" + number);
Intent i = new Intent(Intent.ACTION_SENDTO, uri);
i.setPackage("com.whatsapp");
startActivity(Intent.createChooser(i, ""));
}
//This Will Send Specific Msg to WhatsAPP
public void SelectContactAndMsgSend(View view) {
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();
}
}
//Combining Both Not getting Any result
public void CombiningBoth(View view) {
String number = "Here GOes My Number"; //As i am from india my number Im putting is 91xxxxxxxxxx
Uri uri = Uri.parse("smsto:" + number);
Intent waIntent = new Intent(Intent.ACTION_SENDTO, uri);
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, ""));
} else {
Toast.makeText(this, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
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();
}
}
});
}
}
There are other questions in MMs but none have solved my issue and i simply don't know why!!
String fileName = "/one.png";
File dataFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath());
Toast.makeText(c, String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()), Toast.LENGTH_LONG).show();
if(dataFile.exists())
{
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.setType("image/*");
shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath()+fileName));
Intent new_intent = Intent.createChooser(shareIntent, "Share via");
new_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
c.getApplicationContext().startActivity(new_intent);
}
else
{
Toast.makeText(c, "Not Found", Toast.LENGTH_LONG).show();
}
what is i am doing wrong!!
I am using a button in a listview and want to share text on whatsapp...here is my code...this code is working without taking a listview...but i making a project in which i am using a listview.....
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Try this : https://play.google.com/store/apps/details?id=com.listviewexample");
startActivity(Intent.createChooser(intent, "Share via"));
Try this
public void onClickWhatsApp(View view) {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
String text = "Try this : https://play.google.com/store/apps/details?id=com.listviewexample";
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();
}
}
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 ;
}