英文:
how to open whatsapp or whatsapp business with intent android studio?
问题
我正在使用这段代码,它可以打开WhatsApp,但无法打开WhatsApp Business,有没有办法验证用户安装了哪个版本的WhatsApp?
String contact = phone;
Double amount_total = pac_val_amo + del_fac_amo;
String total = "S/. " + String.format("%.2f", amount_total);
String message = "Su pedido de " + store + " ha llegado, su pago total es de S/. " + total;
String url = "https://api.whatsapp.com/send?phone=" + contact + "&text=" + message;
try {
PackageManager pm = getContext().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(getContext(), "WhatsApp未安装在此设备上。", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
英文:
I'm using this code, and it opens WhatsApp, but it doesn't allow me to open WhatsApp business, is there any way to verify which WhatsApp the user has installed?
String contact = phone;
Double amount_total = pac_val_amo + del_fac_amo;
String total = "S/. " + String.format("%.2f", amount_total);
String message = "Su pedido de " + store + " ha llegado, su pago total es de S/. " + total;
String url = "https://api.whatsapp.com/send?phone=" + contact + "&text=" + message;
try {
PackageManager pm = getContext().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(getContext(), "WhatsApp is not installed on this Device.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
答案1
得分: 5
你可以通过使用其包名com.whatsapp.w4b来打开WhatsApp Business。
在开始意图之前,只需在com.whatsapp和com.whatsapp.w4b之间进行if else检查。
英文:
You can open whatsapp business by using its package name com.whatsapp.w4b
Just do an if else check between com.whatsapp and com.whatsapp.w4b before starting the intent
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论