根据点击的数字打开对话然后意图图像
Open conversation based on clicked number then intent the image
我知道这是一个常见的问题。但我的问题现在不同了。所以我创建了一个分享按钮,如果我点击它会打开 phone 数字列表,如下所示:
所以当我点击其中一个时,它会立即在我点击的 phone 号码的基础上在 whats 应用程序中打开对话。我使用此代码
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);
}
})
}))
而不是根据号码打开对话并发送图像。原来打开whats app,选择发送给谁。
有什么解决办法吗。因为我已经尝试制作 Intent.ACTION_VIEW
它将打开图库。
我的图片url来自数据库
希望这能奏效。只需将路径传递给文件变量的文件位置,并确保传递正确的 phone 数字。
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)
我知道这是一个常见的问题。但我的问题现在不同了。所以我创建了一个分享按钮,如果我点击它会打开 phone 数字列表,如下所示:
所以当我点击其中一个时,它会立即在我点击的 phone 号码的基础上在 whats 应用程序中打开对话。我使用此代码
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);
}
})
}))
而不是根据号码打开对话并发送图像。原来打开whats app,选择发送给谁。
有什么解决办法吗。因为我已经尝试制作 Intent.ACTION_VIEW
它将打开图库。
我的图片url来自数据库
希望这能奏效。只需将路径传递给文件变量的文件位置,并确保传递正确的 phone 数字。
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)