I know this is a common question that has been asked. But my problem is different now. So I create a share button which if I click it will open list of phone number like below :
So when I click one of them, it will immediately open conversation in whats app base on the phone number I click. I use this code
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);
Then I add this code for intent image into the conversation
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);
}
})
}))
Instead of open conversation base on number and send image. It turns out open whats app and choose to who we want to send it.
Is there any solution. Because I already try to make the Intent.ACTION_VIEW
it will open gallery.
My image url is from database