【问题标题】:Open conversation based on clicked number then intent the image根据点击的数字打开对话,然后意图图像
【发布时间】:2019-04-23 14:56:06
【问题描述】:

我知道这是一个常见的问题。但我的问题现在不同了。所以我创建了一个分享按钮,如果我点击它将打开电话号码列表,如下所示:

因此,当我单击其中一个时,它会立即根据我单击的电话号码在什么应用程序中打开对话。我用这个代码

 val url = "https://api.whatsapp.com/send?phone=62"+tempDatas!![position].custHpWa
                                val intent = Intent(Intent.ACTION_VIEW);
                                intent.putExtra(Intent.EXTRA_TEXT,intent.getStringExtra("DESCRIPTION") );
                                intent.data = Uri.parse(url)
                                startActivity(intent);

然后我将这个意图图像的代码添加到对话中

 rvListWa!!.addOnItemTouchListener(RecyclerItemClickListener(this@ShareFileActivity,
            RecyclerItemClickListener.OnItemClickListener { view, position ->

                Glide
                        .with(this@ShareFileActivity)
                        .load(baseURLPicasso+intent.getStringExtra("PICTURE"))
                        .asBitmap()
                        .into(object : SimpleTarget<Bitmap>() {
                            override fun onResourceReady(resource: Bitmap?, glideAnimation: GlideAnimation<in Bitmap>?) {

                                val url = "https://api.whatsapp.com/send?phone=62"+tempDatas!![position].custHpWa
                                val intent = Intent(Intent.ACTION_SEND);
                                intent.putExtra(Intent.EXTRA_TEXT,intent.getStringExtra("DESCRIPTION") );
                                val path = MediaStore.Images.Media.insertImage(getContentResolver(), resource, "", null);
                                val image = Uri.parse(path);

                                intent.data = Uri.parse(url)
                                intent.putExtra(Intent.EXTRA_STREAM, image);
                                intent.setType("image/*");
                                startActivity(intent);


                            }

                        })
            }))

而不是基于数字和发送图像的开放对话。结果是打开什么应用程序并选择我们要发送给谁。

有什么解决办法。因为我已经尝试使Intent.ACTION_VIEW 它将打开画廊。

我的图片网址来自数据库

【问题讨论】:

标签: android image android-intent kotlin whatsapp


【解决方案1】:

希望这可行。只需将路径传递给文件变量的文件位置,并确保传递正确的电话号码。

    val sendIntent = Intent("android.intent.action.SEND")
    val f = File("path to the file")
    val uri = Uri.fromFile(f)
    sendIntent.component = ComponentName("com.whatsapp", "com.whatsapp.ContactPicker")
    sendIntent.type = "image"
    sendIntent.putExtra(Intent.EXTRA_STREAM, uri)
    sendIntent.putExtra("jid", PhoneNumberUtils.stripSeparators("91**********") + "@s.whatsapp.net")
    sendIntent.putExtra(Intent.EXTRA_TEXT, "sample text you want to send along with the image")
    startActivity(sendIntent)

【讨论】:

  • 它不起作用先生@Nagendra ..当我点击whatsapp图标它什么也不做
  • 您的代码中的电话号码是否与您的whatsapp联系号码匹配?
  • PhoneNumberUtils.stripSeparators(tempDatas!![position].custHpWa) , custHpWa 是 081944877002,印度尼西亚代码
  • 我将这个 com.whatsapp.ContactPicker 更改为 com.whatsapp.Conversation,它可以工作,但仅用于打开 convo ,但我的号码变为 +081944877002,图像也不包括
  • 请确保您传递了正确的图片 url,否则它会显示错误消息,例如错误共享媒体文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-21
  • 2018-11-02
  • 2021-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多