WhatsApp Chat Application Android Studio

WhatsApp Chat Application Android Studio – In this article i will explain how develop chat application like whatapp facebook using java in Android Studio platform. Before coming android mobile phones everyone use normal message to share information in offline but when coming android cell phones everybody switch on chat applications like whatsapp, Facebook, Instagram,hike,viber and more popular chat apps are available in google play store.

There are more drawback we faced before coming on high speed internet and android mobile phones because we cant send images videos documents in normal message application. That time we need one social networking website like whatsapp to send and share the information within a minute in digital way. In this century nobody lives without android phones.

Chat Application Android Studio

Okay lets start to develop own chat application like whatsapp. WhatsApp is a big platform for share the information and send image,videos,documents & more formats. In this article also you can learn and create one application which is match on social networking chat app. As usual first create one project and choose some activity after making the setup you can create more directories for store the server data and client requesting data.

This project source code is very long so can’t easily understand the code when you have no idea about java. If you well known then easily pickup and understand the codes and also customize the application user interface as our own taste or based on the customer reviews.

Create Android WhatsApp Chat App

Here we additionally create 12 java files and xml files to communicate and receive messages from server. I have to use firebase database for store and retrieve information through the HTTP. Code are clearly separated so you dont worry about facing difficulties. Open default class of MainActivity.java file and add following below code ,

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.tabs.TabLayout;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity {
    private Toolbar mToolbar;
    private ViewPager myViewPager;
    private TabLayout myTabLayout;
    private TabsAccessorAdapter myTabsAccessorAdapter;
    private FirebaseUser currentUser;
    private FirebaseAuth mAuth;
    private DatabaseReference RootRef;
    private String currentUserID;
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mAuth = FirebaseAuth.getInstance();
        currentUser = mAuth.getCurrentUser();
        RootRef = FirebaseDatabase.getInstance().getReference();
        mToolbar = (Toolbar) findViewById(R.id.main_page_toolbar);
        setSupportActionBar(mToolbar);
        getSupportActionBar().setTitle("WhatsApp");
        myViewPager = (ViewPager) findViewById(R.id.main_tabs_pager);
        myTabsAccessorAdapter = new TabsAccessorAdapter(getSupportFragmentManager());
        myViewPager.setAdapter(myTabsAccessorAdapter);
        myTabLayout = (TabLayout) findViewById(R.id.main_tabs);
        myTabLayout.setupWithViewPager(myViewPager);
    }
    @Override
    protected void onStart()
    {
        super.onStart();
        if (currentUser == null)
        {
            SendUserToLoginActivity();
        }
        else
        {
            VerifyUserExistence();
        }
    }
    @Override
    protected void onStop()
    {
        super.onStop();
        if (currentUser != null)
        {
            updateUserStatus("offline");
          }
    }
    private void VerifyUserExistence() {
        String currentUserID = mAuth.getCurrentUser().getUid();
        RootRef.child("Users").child(currentUserID).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                if((dataSnapshot.child("name").exists()))
                {
                    Toast.makeText(MainActivity.this, "Welcome", Toast.LENGTH_SHORT).show();
                }
                else
                {
                    SendUserToSettingsActivity();
                }
            }
            @Override
            public void onCancelled(@NonNull DatabaseError databaseError) {
            }
        });
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        getMenuInflater().inflate(R.menu.options_menu,menu);
        return true;
    }
    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
         super.onOptionsItemSelected(item);
         if(item.getItemId() == R.id.main_create_group_option)
         {
             RequestNewGroup();
         }
        if(item.getItemId() == R.id.main_settings_option)
        {
            SendUserToSettingsActivity();
        }
        if(item.getItemId() == R.id.main_logout_option)
        {
            updateUserStatus("offline");
           mAuth.signOut();
           SendUserToLoginActivity();
        }
        if (item.getItemId() == R.id.main_find_friends_option)
        {
            SendUserToFindFriendsActivity();
        }
         return true;
    }
    private void RequestNewGroup()
    {
       AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this,R.style.AlertDialog);
       builder.setTitle("Create Group");
       final EditText groupNameField = new EditText(MainActivity.this);
       groupNameField.setHint("Eg. ThunderBuddies");
       builder.setView(groupNameField);
       builder.setPositiveButton("Create", new DialogInterface.OnClickListener()
       {
           @Override
           public void onClick(DialogInterface dialogInterface, int i)
           {
              String groupName = groupNameField.getText().toString();
               if (TextUtils.isEmpty(groupName))
               {
                   Toast.makeText(MainActivity.this, "Please write Group Name...", Toast.LENGTH_SHORT).show();
               }
               else
               {
                   CreateNewGroup(groupName);
               }
           }
       });
       builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
       {
           @Override
           public void onClick(DialogInterface dialogInterface, int i) {
              dialogInterface.cancel();
           }
       });
       builder.show();
    }
          }
      });
    }
    private void SendUserToLoginActivity() {
        Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class);
        loginIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(loginIntent);
    }
    private void SendUserToSettingsActivity() {
        Intent settingsIntent = new Intent(MainActivity.this, SettingsActivity.class);
        startActivity(settingsIntent);
    }
    private void SendUserToFindFriendsActivity()
    {
        Intent findFriendsIntent = new Intent(MainActivity.this, FindFriendsActivity.class);
        startActivity(findFriendsIntent);
    }
    
}

Still need to develop more java files for integrate with back-end of Firebase and connect the http request for get the client response from server side. http protocol used for get and store user data from a database.

Also Read – Gold Saving Scheme App Android

Firebase Store Data Android

Back-end is you wish here i use Firebase because we can easily connect with android studio when to compared to other databases and its developed and maintained by google community. In this reason only enough to select Firebase.

I have store most of major files like images videos documents are stored and accessed in the Firebase and login account create fields are stored in SQLite because its very efficient and speed.

Notifications & Create Group

Here we develop same as WhatsApp application which include same notifications group creation and more feature. Additionally we add one more advantage that is accept and reject the user who request from the other user. It means one user like to spoke with then he/she is request you to send and receive message like Facebook application. WhatsApp have does not this feature but here we add this for unknown persons.

Screenshots – WhatsApp Chat Application Android

Before downloading the project once you can check the screenshots its satisfied your requirements. If okay then you can download the WhatsApp chat application project in below button.

Download Source Code

This project have more features so just and download and enjoy new WhatsApp application, new user interface and new advantages. If you face any bugs, comment below i will try to fix your queries.

Leave a Reply