繁体   English   中英

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

[英]open specific whatsapp contact from my android app

我想通过单击一个按钮在我的 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);

请指导我。

请使用下面的代码来实现这一点。

    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();
        }

我正在使用这个:

            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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM