In this blog, we have to create/implement Android Java code to develop an open WhatsApp app directly in Android Studio. So, we provide direct code in this blog.
Before creating the project, we have provided some assets to support its development.
Implement the App Color Code in the “colors.xml” file.
Here, we have to insert the color code to customise your application project.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
Replace “Action Bar” with “No Action Bar”.
<style name=”Theme.ThakurPrasad2026″ parent=”Theme.MaterialComponents.DayNight.NoActionBar”>
<!– Primary brand color. –>
<item name=”colorPrimary”>@color/purple_500</item>
<item name=”colorPrimaryVariant”>@color/purple_700</item>
<item name=”colorOnPrimary”>@color/white</item>
<!– Secondary brand color. –>
<item name=”colorSecondary”>@color/teal_200</item>
<item name=”colorSecondaryVariant”>@color/teal_700</item>
<item name=”colorOnSecondary”>@color/black</item>
<!– Status bar color. –>
<item name=”android:statusBarColor”>?attr/colorPrimaryVariant</item>
<!– Customize your theme here. –>
</style>
Implement the layout code for “activity_main.xml” for demo purposes, as shown below.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.card.MaterialCardView
android:id="@+id/whatsAppButton"
android:layout_width="300dp"
android:layout_height="60dp"
android:layout_margin="4dp"
android:clickable="true"
android:focusable="true"
app:cardBackgroundColor="#00BD19"
app:cardCornerRadius="48dp"
app:cardElevation="3dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Contact Via WhatsApp"
android:textColor="@color/white"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Implement the Code in the “MainActivity.Java” file given below.
First, we have implemented the variable above in the “OnCreate” method.
MaterialCardView cardView;
Now, we have to implement “WhatsApp Open” Java code under the “OnCreate” method.
cardView = findViewById(R.id.whatsAppButton);
cardView.setOnClickListener(view -> {
String whatsappURL = "https://wa.me/+911234567890?text=Hi, I need your help?";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(whatsappURL));
startActivity(intent);
});
Thank You!