To integrate WhatsApp with an Android application using Intent, you can use the following code.
Java Example
To Send a message to a specific phone number:
Intent sendIntent = new Intent("android.intent.action.SEND");
sendIntent.setType("text/plain");
sendIntent.putExtra("android.intent.extra.TEXT", "Your message here");
sendIntent.putExtra("jid", "PHONE_NUMBER_HERE");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
To share a file:
Intent shareIntent = new Intent("android.intent.action.SEND");
shareIntent.setType("image/jpeg"); // Or any other file type
shareIntent.putExtra("android.intent.extra.STREAM", Uri.parse("file:///path/to/your/file.jpg"));
shareIntent.putExtra("jid", "PHONE_NUMBER_HERE");
shareIntent.setPackage("com.whatsapp");
startActivity(shareIntent);
Using Kotlin:
To Send a message to a specific phone number:
val sendIntent = Intent("android.intent.action.SEND")
sendIntent.type = "text/plain"
sendIntent.putExtra("android.intent.extra.TEXT", "Your message here")
sendIntent.putExtra("jid", "PHONE_NUMBER_HERE")
sendIntent.setPackage("com.whatsapp")
startActivity(sendIntent)
To share a file:
val shareIntent = Intent("android.intent.action.SEND")
shareIntent.type = "image/jpeg" // Or any other file type
shareIntent.putExtra("android.intent.extra.STREAM", Uri.parse("file:///path/to/your/file.jpg"))
shareIntent.putExtra("jid", "PHONE_NUMBER_HERE")
shareIntent.setPackage("com.whatsapp")
startActivity(shareIntent)
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!