[英]open specific whatsapp contact from my android app
I want to open a specific contact in my whatsapp by clicking a button I am using this code but it is not working.我想通过单击一个按钮在我的 whatsapp 中打开一个特定的联系人我正在使用此代码,但它不起作用。
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Uri uri = Uri.parse("smsto:"+"923000000000");
Intent i = new Intent(Intent.ACTION_SENDTO,uri);
i.setPackage("com.whatsapp");
startActivity(i);
Please guide me.请指导我。
Kindly use below code to achieve this.请使用下面的代码来实现这一点。
String contact = "+92 3122804640"; // use country code with your phone number
String url = "https://api.whatsapp.com/send?phone=" + contact;
try {
PackageManager pm = getApplicationContext().getPackageManager();
pm.getPackageInfo("com.whatsapp", PackageManager.GET_ACTIVITIES);
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(MainActivity.this, "Whatsapp app not installed in your phone", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
I am Using This:我正在使用这个:
String phone = "+8801510101010";
PackageManager packageManager = MainActivity.this.getPackageManager();
Intent i = new Intent(Intent.ACTION_VIEW);
try {
String url = "https://api.whatsapp.com/send?phone="+ phone;
i.setPackage("com.whatsapp");
i.setData(Uri.parse(url));
if (i.resolveActivity(packageManager) != null) {
MainActivity.this.startActivity(i);
}
} catch (Exception e){
e.printStackTrace();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.