简体   繁体   English

从我的 android 应用程序打开特定的 whatsapp 联系人

[英]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.

相关问题 如何通过特定联系人从其他应用程序打开Whatsapp? - How to open Whatsapp from other app with a specific contact? 如何从我的 Android 应用程序通过 WhatsApp 向特定联系人发送消息? - How can I send message to specific contact through WhatsApp from my android app? 如何在Android中添加联系人,例如Skype,本机联系人应用中的whatsapp? - How to add contact in Android like skype, whatsapp in native contact app? 如何使用意图从我的应用程序打开 whatsapp 主屏幕 - how to open whatsapp home screen from my app using intents 使用特定联系人打开 LINE android 应用程序的聊天屏幕 - Open chat screen of LINE android app with a specific contact 如何从WhatsApp到Android中的我的应用程序获取pdf文件数据? - How to get pdf file data from whatsapp to my app in android? 直接从我的 android 应用程序发送 whatsapp 消息 - Send whatsapp message directly from my android app 如何在Android移动开发中的WhatsApp应用程序中访问联系方式? - How to access the contact details within the WhatsApp app in android mobile development? WhatsApp 如何检测联系人列表中的谁使用该应用程序? - How does WhatsApp detect who from the contact list uses the app? 将电话号码或 CONTACT_ID 从 android 联系方式传递给活动(whatsapp 之类) - Passing phone number or CONTACT_ID from android contact details to activity (whatsapp like)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM