How to Create User Profile System in Android Studio V-1|| The Developer 2.0

[rtcl_listings]

Hello guys in this tutorial video I am telling about how you can create a profile system for your android app. In which a user can view their profile details and can change and update their profile details also user can change his profile password. Here I use Volley libary to call data from data base. Alll data are coming in Json format so we need to use json encode r and decode to get the actual value.

Watch Tutorial Video:

Download Php file (profile.php):

 

Click on Below button and complete task showed in pop up to Download the prilfe.php file


 

Source Code of profile.xml file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Signup">

    <TextView
        android:id="@+id/textView"
        android:layout_width="222dp"
        android:layout_height="61dp"
        android:text="Your Profile Details"
        android:textAlignment="center"
        android:textColor="#00BFA5"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.401"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.028" />

    <EditText
        android:id="@+id/user_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Your PUBG ID"
        android:inputType="textPersonName"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.393"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.161" />

    <EditText
        android:id="@+id/email"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Your Email"
        android:inputType="textEmailAddress"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.393"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.268" />

    <EditText
        android:id="@+id/phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Your Phone Number"
        android:inputType="phone"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.383"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.372" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="241dp"
        android:layout_height="47dp"
        android:layout_marginStart="57dp"
        android:layout_marginTop="344dp"
        android:text="Change Password"
        android:textAlignment="center"
        android:textColor="#B388FF"
        android:textSize="24sp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <EditText
        android:id="@+id/password"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Old Pasword"
        android:inputType="textPassword"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.383"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.732" />

    <EditText
        android:id="@+id/p_new_pass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="New Password"
        android:inputType="textPassword"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.393"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.84" />

    <Button
        android:id="@+id/p_changepasword"
        android:layout_width="215dp"
        android:layout_height="57dp"
        android:background="#00BFA5"
        android:text="Change Password"
        android:textColor="#E1DEE4"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.387"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.97" />

    <Button
        android:id="@+id/p_update"
        android:layout_width="186dp"
        android:layout_height="52dp"
        android:layout_marginStart="86dp"
        android:layout_marginTop="260dp"
        android:background="#A7FFEB"
        android:text="UPDATE"
        android:textAlignment="center"
        android:textSize="18sp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Source Code of Profile.java file

package com.sanjay.tournament;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

public class Profile extends AppCompatActivity {

    EditText userid, email, phone;
    String password,profileurl="https://quizeapp.000webhostapp.com/PUBG/profile.php";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile);
        userid = findViewById(R.id.user_id);
        email = findViewById(R.id.email);
        phone = findViewById(R.id.phone);
        getprofiledeatils();

    }

    public void getprofiledeatils() {
        SharedPreferences sharedPreferences = getSharedPreferences("com.sanjay.tournament_login_status", MODE_PRIVATE);
        final String check = sharedPreferences.getString("myusername", "null");
        RequestQueue queue = Volley.newRequestQueue(this);
        String url ="https://quizeapp.000webhostapp.com/PUBG/profile.php";

        StringRequest strRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>()
                {
                    @Override
                    public void onResponse(String response)
                    {
                        try {
                            JSONObject object = new JSONObject(response);
                            userid.setText(object.getString("user_id") );
                            email.setText(object.getString("Email") );
                            phone.setText(object.getString("Phone") );

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error)
                    {

                    }
                })
        {
            @Override
            protected Map<String, String> getParams()
            {
                Map<String, String> params = new HashMap<String, String>();
                params.put("username", check);
                return params;
            }
        };

        queue.add(strRequest);
    }
}