Hello Everyone I hope you all are doing good.
Today we will create one most required app that we need in our day-to-day life. We are Creating one App that Sends WhatsApp Messages without saving the Number.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Number"
android:id="@+id/edtnum"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edtsms"
android:hint="Msg Here"
android:inputType="text"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send it!!"
android:layout_gravity="center"
android:id="@+id/btnsend"/>
</LinearLayout>
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val btnSend : Button = findViewById(R.id.btnsend)
val txtNumber : EditText = findViewById(R.id.edtnum)
val txtMsg : EditText = findViewById(R.id.edtsms)
btnSend.setOnClickListener {
if(number.text.isNotEmpty() && msg.text.isNotEmpty()){
val packageManager : PackageManager = packageManager
val i = Intent(Intent.ACTION_VIEW)
val url = "https://api.whatsapp.com/send?phone=" + number.text.toString() + "&text="+ URLEncoder.encode(msg.text.toString(),"UTF-8")
i.setPackage("com.whatsapp")
i.data = Uri.parse(url)
if(i.resolveActivity(packageManager) != null){
startActivity(i)
}
}else{
Toast.makeText(this, "Please Enter Msg Or Number !!", Toast.LENGTH_LONG).show()
} }
}
}
0 Comments