Thursday, November 21, 2019

Common Hide Keyboard in an application

public static void hideKeyboard(Context context) {
        try {
            InputMethodManager inputManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(((Activity) context).getCurrentFocus().getWindowToken(), 0);
        } catch (Exception e) {
            Log.e(TAG, "Sigh, can't even hide keyboard " + e.getMessage());
        }
    }

Saturday, November 9, 2019

Sending data from one activity to other using Intent



To send data from activity one


                Intent intent=new Intent(this,nextactivity.class);
                intent.putExtra("key ",value);
                context.startActivity(intent);

 To receive data in activity two

Intent intent=getIntent().getextras();

String s =intent.getstring("key provided in class one");


Showing pdf in a webview without downloading


import android.app.DownloadManager;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.renderscript.Sampler;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.view.ViewGroup;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.amazonaws.Request;

import javax.security.auth.callback.Callback;

public class WebViewActivity extends AppCompatActivity {
    String url;
    WebView webView;
    ProgressDialog progressBar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview_pdf);
        url = getIntent().getStringExtra("url");
        webView = findViewById(R.id.webViewpdf);
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        progressBar=ProgressDialog.show(this,"","loading");

//"https://docs.google.com/gview?embedded=true&url="  this is the online google viewer

        webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + url);


        webView.setWebViewClient(new WebViewClient() {

// this is used for showing the progress until the page stops loading
            public void onPageFinished(WebView view, String url) {
                if (progressBar.isShowing()) {
                    progressBar.dismiss();
                }
            }
        });


    }
}

Round image corners at runtime using Glide #android #Glide


Round image corners at runtime using Glide library

In this post, we will check how to make Image corners round at runtime.
               

 RequestOptions requestOptions = new RequestOptions();
   requestOptions = requestOptions.transforms(new CenterCrop(),newRoundedCornersTransformation(39,0,RoundedCornersTransformation.CornerType.TOP_RIGHT));
              
  Glide.with(this)
                        .load(userData.getCoverpicture())
                        .apply(requestOptions)
                        .into(coverpic);

Sending data from one activity to other using bundle

Send data from  Activity

Intent intent =new Intent(this,nextactvitiy.class);
Bundle bundle=new Bundle();
bundle.putString("key",value);
bundle.putString("another key",another value);
intent.putExtras(bundle);
startactivity(intent);


Get data in another Activity

Bundle bundle=getIntent().getExtras();
String s =bundle.getString("key");
String s2=bundle.getString("key2");

Friday, November 1, 2019

Comparing Two dates in Android

 SimpleDateFormat  simpledateformat  = new SimpleDateFormat("yyyy-MM-dd"); 
        Date d1 = simpledateformat  .parse("2018-03-31"); 
        Date d2 = simpledateformat  .parse("2012-03-31"); 
  
        if (d1before  d2) { 
  
            System.out.println("Date1 is before Date2"); 
        } 
  
        else if (d1 after d2) { 
              System.out.println("Date1 is afterrDate2"); 
  
        }



Kindly note:The date formats of both the dates must be same.

Tuesday, October 29, 2019

CardView in android

Cardview is another material added for designing a layout.It resprents your designin a card manner with the corner radius and  drop elevation (shadow).

Steps to Add CardView in your android studio:

1. Adding Design Dependency

       Build Gradle (Module:App)


dependencies {

implementation 'com.android.support:design:28.0.0'

}


2. Add the <android.support.v7.widget.CardView> widget to your layout and place UI widgets like TextViews, ImageViews inside it.


activity_main.xml

<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"  
  android:background="@drawable/login_back"  
  tools:context=".LoginActivity">

    <android.support.v7.widget.CardView   
     android:layout_width="match_parent"   
     android:layout_height="wrap_content"    
    android:layout_margin="20dp"      
  android:background="@drawable/ic_cardview_corner"  
      app:cardCornerRadius="15dp"      
  app:cardElevation="20dp"     
   app:layout_constraintBottom_toBottomOf="parent"   
     app:layout_constraintLeft_toLeftOf="parent"     
   app:layout_constraintRight_toRightOf="parent"    
    app:layout_constraintTop_toTopOf="parent">


        <LinearLayout          
  android:id="@+id/linear_login"     
  android:layout_width="match_parent"  
  android:layout_height="wrap_content"  
  android:orientation="vertical">


 <android.support.design.widget.TextInputLayout     
           android:id="@+id/text_Username"       
         android:layout_width="match_parent"          
      android:layout_height="wrap_content">


                <EditText     
               android:id="@+id/username_l"  
                  android:layout_width="match_parent"    
                android:layout_height="wrap_content"     
               android:hint="Username"                
    android:textColorHint="#fff" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout      
          android:id="@+id/text_password"             
   android:layout_width="match_parent"              
  android:layout_height="wrap_content">


                <EditText                  
      android:id="@+id/password_l"              
      android:layout_width="match_parent"             
      android:layout_height="wrap_content"              
      android:hint="Password"                  
      android:textColorHint="#fff" />
            </android.support.design.widget.TextInputLayout>

            <Button                
   android:id="@+id/login"             
   android:layout_width="match_parent"         
   android:layout_height="wrap_content"
    android:text="Login" />

            <Button        
        android:id="@+id/newuser"    
        android:layout_width="match_parent"   
       android:layout_height="wrap_content"         
       android:text="Create New User" />

        </LinearLayout>
    </android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>








3.Adding Boundary line to the CardView                                                                                             


Drawable                                                                                                                                

ic_caredview_boundary.xml                                                                                                                     

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <stroke    
    android:width="2dp"
    android:color="#fff">
</stroke>

</shape>                                                                                                                           






Sunday, October 20, 2019

Multiple File Picker in android

Multiple File Picker Library ,with this a user can pick multiple files for uploading to the server using retrofit or volley..


Dependency used for File Picker

implementation 'com.github.jaiselrahman:FilePicker:1.2.2'



Java File



package com.example.filepicker;

import android.content.Intent;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.jaiselrahman.filepicker.activity.FilePickerActivity;
import com.jaiselrahman.filepicker.config.Configurations;
import com.jaiselrahman.filepicker.model.MediaFile;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    ArrayList<CustomMediaFile> imageArrayList;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode==123 && resultCode==RESULT_OK){
            ArrayList<MediaFile> files = data.getParcelableArrayListExtra(FilePickerActivity.MEDIA_FILES);
            //Do something with files
            for (int i=0; i<files.size();i++){
                Log.d("MyPaths",files.get(i).getPath());
            }

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pickFiles();
            }
        });

    }
    public void pickFiles(){
        imageArrayList = new ArrayList<>();
        Intent filePickerIntent = new Intent(MainActivity.this, FilePickerActivity.class);
        filePickerIntent.putExtra(FilePickerActivity.CONFIGS, new Configurations.Builder()
                .setCheckPermission(true)
                .setMaxSelection(1)
                .setShowImages(false)
                .enableImageCapture(false)
                .setShowVideos(false)
                .setShowAudios(false)
                .setShowFiles(true)
                .setSuffixes(new String[]{"pdf", "doc", "xls"})
                .build());
        startActivityForResult(filePickerIntent, 123);
    }
}

One ProgressBar for whole Project .

ProgressBar can be used in whole Project by creating a single class.THis is demonstrated By the following code...


XML for ProgressBar...

<?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:layout_width="match_parent"    
 android:layout_height="match_parent"   
 tools:context=".MainActivity">

    <ProgressBar       
 android:layout_width="wrap_content"       
 android:layout_height="wrap_content"      
 android:id="@+id/progressbar"      
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintLeft_toLeftOf="parent"     
 app:layout_constraintRight_toRightOf="parent"       
 app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>



Java File


package com.a.progressbaee;

import android.app.Dialog;
import android.content.Context;

public class ProgressBar extends Dialog {
    public ProgressBar(Context context) {
        super(context);
        setContentView(R.layout.activity_main);

    }

    @Override    public void show() {
        super.show();
    }

    @Override    public void hide() {
        super.hide();
    }

    @Override    public void dismiss() {
        super.dismiss();
    }

    @Override    public void cancel() {
        super.cancel();
    }
}



This can be called in other classes By just 

providing the progressbar class name and creating its object..

ProgressBar progressbar;


TO show progressbar

progressbar.show();


To hide the progressbar

progressbar.hide();

To dismiss the Progrressbar

progressbar.dismiss();

To cancel the progressbar

progressbar.cancel();




Tuesday, July 30, 2019

Volley for loading data

Volley is a REST  network library which is  used to send and get data from the server we need to do json parsing to fetch data from the server below s the example for the same.


User permission

<uses-permission android:name="android.permission.INTERNET" />

Dependencies

implementation 'com.android.volley:volley:1.1.0'

Java class

package com.vishalsingh.practice;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

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 com.squareup.picasso.Picasso;

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

import java.util.HashMap;
import java.util.Map;

public class VolleyActivity extends AppCompatActivity {
    TextView textView;
    Button button;
    String url="your url ";
    ImageView imageView;
    String Imageurl;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_volley);

        textView=findViewById(R.id.textview);
        button=findViewById(R.id.button);
        imageView=findViewById(R.id.Imageview);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StringRequest sr=new StringRequest(1, url, new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jo=new JSONObject(response);
                            JSONArray jo1=jo.getJSONArray("Response");
                            JSONObject jo2=jo1.getJSONObject(0);
                            String data1=jo2.getString("Name");
                            Imageurl=jo2.getString("Image");
                            Picasso.get().load(Imageurl).into(imageView);
                            textView.setText(data1+"\n");



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

                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                    }
                }){
                    @Override
                    public   Map<String,String> getParams(){
                        Map<String, String> params = new HashMap<>();
                        params.put("UserId", "0d770e2b-eeff-4652-8282-5c756941d280");
                        return params;
                }};
                RequestQueue rq= Volley.newRequestQueue(VolleyActivity.this);
                rq.add(sr);
            }
        });


    }
}

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=".VolleyActivity">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:text="fetch"
        app:layout_constraintTop_toTopOf="parent"/>
    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        android:id="@+id/Imageview"

        app:layout_constraintTop_toBottomOf="@+id/button"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textview"
        app:layout_constraintTop_toBottomOf="@+id/Imageview"/>

</android.support.constraint.ConstraintLayout>

Sample Json

{
"Status":true,
"Error":
{
"Code":0,
"Message":""
},
"Response":
[{"Name":"Shubham Shrivastava",
"Image":"http://103.115.194.111:906/Readers/uploads/Screenshot_20190424-202039.jpg",
"Gender":"Mr.",
"DateOfBirth":"26 Dec 2018",
"Address":"Noida",
"Country":"INDIA",
"PinCode":"485001",
"EmailId":"shri.shubham86@gmail.com",
"MobileNo":"9074762379",
"isPartner":"No",
"City":"",
"State":"Madhya Pradesh",
"Booth":"Other",
"Constituency":"Satna",
"Assembly":"Satna",
"Citizenship":null}
]
}

Monday, June 24, 2019

Soap in android #android #soap protocol #xml

Today I will explain to you how to load data using soap. Soap is not much used today but it has its own features like security so it is used even today

Points to Note
SOAP is a communication protocol designed to communicate via Internet.

SOAP can extend HTTP for XML messaging.

SOAP provides data transport for Web services.

SOAP can exchange complete documents or call a remote procedure.

SOAP can be used for broadcasting a message.

SOAP is platform- and language-independent.

SOAP is the XML way of defining what information is sent and how.

SOAP enables client applications to easily connect to remote services and invoke remote methods.


Manifest file


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"    
package="com.vishalsingh.soap">
<uses-permission android:name="android.permission.INTERNET"></uses-permission> 
       <application        
 android:usesCleartextTraffic="true"  
 android:allowBackup="true"       
 android:icon="@mipmap/ic_launcher"      
 android:label="@string/app_name"       
 android:roundIcon="@mipmap/ic_launcher_round" 
 android:supportsRtl="true"       
 android:theme="@style/AppTheme">     
   <activity android:name=".MainActivity">       
     <intent-filter>            
    <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />    
        </intent-filter>    
    </activity>  
  </application>
</manifest>

Java file


package com.vishalsingh.soap;
import android.content.Context;
import android.os.AsyncTask;
import android.os.PowerManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;import android.widget.TextView;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {

    SoapObject result;   
 Workertask workertask;   
 TextView textView; 
   String mytext;    
String SchId;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.textview);

        workertask = new Workertask();
        workertask.execute();

    }

    private class Workertask extends AsyncTask {
        String[] separated;
       int count = 0; 
       String authenticated;

        @Override
        protected Object doInBackground(Object[] objects) {
            String SOAP_ACTION = "Your Soap Action";
            String NAMESPACE = "Your namespace";
            String METHOD_NAME = "your method";
            String URL = "your url";
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            request.addProperty("un", "sumit");
            request.addProperty("pass", "billy");
            request.addProperty("DeviceId", "00");
            request.addProperty("Technology", "android");
            request.addProperty("ISNew", "0");
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                    SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet = true;
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            try {
                androidHttpTransport.call(SOAP_ACTION, envelope);
                result = (SoapObject) envelope.bodyIn;
            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();            }
            count = result.getPropertyCount();
            authenticated = result.getProperty(0).toString();
            separated = new String[count];
            separated = (authenticated).split("%");
            SchId = separated[0]; 
          String SchName = separated[1];
          String fName = separated[2];

            return null;
        }

        @Override
        protected void onPostExecute(Object o) {
            textView.setText(SchId);
            super.onPostExecute(o);
        }
    }
}


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=".MainActivity">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
       android:id="@+id/textview" 
       app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" 
       app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

Thursday, June 20, 2019

Retrofit using post method Complex json

Retrofit is network library which uses http request to get data from the server . I  am going to give you a example by using complex json and post method to load data .

Manifest file


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"  
  package="com.vishalsingh.retrofit">
    <uses-permission android:name="android.permission.INTERNET" />
    <application       
      android:allowBackup="true"   
      android:icon="@mipmap/ic_launcher"  
      android:label="@string/app_name"    
      android:networkSecurityConfig="@xml/actions"  
      android:roundIcon="@mipmap/ic_launcher_round"  
      android:supportsRtl="true"     
   android:theme="@style/AppTheme">    
    <activity android:name=".MainActivity" />   
     <activity android:name=".Main2Activity">     
       <intent-filter>           
     <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>  
      </activity>
        <meta-data          
  android:name="com.google.android.actions"     
       android:resource="@xml/actions" />  
  </application>
</manifest>

Library pojo.java


package com.vishalsingh.retrofit.Pojo;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Library {

    @SerializedName("Status")
    @Expose    private Boolean status;  
  @SerializedName("Error")
    @Expose    private Error error;  
  @SerializedName("Response")
    @Expose  
  private List<Response> response = null;
    public Boolean getStatus() {
        return status;    }

    public void setStatus(Boolean status) {
        this.status = status;    }

    public Error getError() {
        return error;    }

    public void setError(Error error) {
        this.error = error;    }

    public List<Response> getResponse() {
        return response;    }

    public void setResponse(List<Response> response) {
        this.response = response;    }

}

Error pojo.java


package com.vishalsingh.retrofit.Pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Error {

    @SerializedName("Code")
    @Expose    private Integer code;   
 @SerializedName("Message")
    @Expose    private String message;
    public Integer getCode() {
        return code;    }

    public void setCode(Integer code) {
        this.code = code;    }

    public String getMessage() {
        return message;    }

    public void setMessage(String message) {
        this.message = message;    }

}

Response pojo.java


package com.vishalsingh.retrofit.Pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Response {

    @SerializedName("Name")
    @Expose    private String name;    @SerializedName("Image")
    @Expose    private String image;    @SerializedName("Gender")
    @Expose    private String gender;    @SerializedName("DateOfBirth")
    @Expose    private String dateOfBirth;    @SerializedName("Address")
    @Expose    private String address;    @SerializedName("Country")
    @Expose    private String country;    @SerializedName("PinCode")
    @Expose    private String pinCode;    @SerializedName("EmailId")
    @Expose    private String emailId;    @SerializedName("MobileNo")
    @Expose    private String mobileNo;    @SerializedName("isPartner")
    @Expose    private String isPartner;    @SerializedName("City")
    @Expose    private String city;    @SerializedName("State")
    @Expose    private String state;    @SerializedName("Booth")
    @Expose    private String booth;    @SerializedName("Constituency")
    @Expose    private String constituency;    @SerializedName("Assembly")
    @Expose    private String assembly;    @SerializedName("Citizenship")
    @Expose    private Object citizenship;
    public String getName() {
        return name;    }

    public void setName(String name) {
        this.name = name;    }

    public String getImage() {
        return image;    }

    public void setImage(String image) {
        this.image = image;    }

    public String getGender() {
        return gender;    }

    public void setGender(String gender) {
        this.gender = gender;    }

    public String getDateOfBirth() {
        return dateOfBirth;    }

    public void setDateOfBirth(String dateOfBirth) {
        this.dateOfBirth = dateOfBirth;    }

    public String getAddress() {
        return address;    }

    public void setAddress(String address) {
        this.address = address;    }

    public String getCountry() {
        return country;    }

    public void setCountry(String country) {
        this.country = country;    }

    public String getPinCode() {
        return pinCode;    }

    public void setPinCode(String pinCode) {
        this.pinCode = pinCode;    }

    public String getEmailId() {
        return emailId;    }

    public void setEmailId(String emailId) {
        this.emailId = emailId;    }

    public String getMobileNo() {
        return mobileNo;    }

    public void setMobileNo(String mobileNo) {
        this.mobileNo = mobileNo;    }

    public String getIsPartner() {
        return isPartner;    }

    public void setIsPartner(String isPartner) {
        this.isPartner = isPartner;    }

    public String getCity() {
        return city;    }

    public void setCity(String city) {
        this.city = city;    }

    public String getState() {
        return state;    }

    public void setState(String state) {
        this.state = state;    }

    public String getBooth() {
        return booth;    }

    public void setBooth(String booth) {
        this.booth = booth;    }

    public String getConstituency() {
        return constituency;    }

    public void setConstituency(String constituency) {
        this.constituency = constituency;    }

    public String getAssembly() {
        return assembly;    }

    public void setAssembly(String assembly) {
        this.assembly = assembly;    }

    public Object getCitizenship() {
        return citizenship;    }

    public void setCitizenship(Object citizenship) {
        this.citizenship = citizenship;    }

}

Apiclient.java
package com.vishalsingh.retrofit;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class APIClient {
    private static Retrofit retrofit = null;
    static Retrofit getClient() {

        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();   
     interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);       
 OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();


        retrofit = new Retrofit.Builder()
                .baseUrl("Your base ur")
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        


        return retrofit;    }
}
ApiInterface.java
note: name it as new api
package com.vishalsingh.retrofit;
import com.vishalsingh.retrofit.Pojo.Library;
import java.util.List;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;

 interface NewApi {


     @FormUrlEncoded     
     @POST(" Your post method ?")
     Call<Library> doCreateUserWithField(@Field("UserId") String UserId);}


MainActivity.java




package com.vishalsingh.retrofit;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;import android.widget.TextView;
import android.widget.Toast;
import com.vishalsingh.retrofit.Pojo.Library;
import java.util.HashMap;import java.util.List;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class Main2Activity extends AppCompatActivity {
    TextView text1;   
 NewApi apiInterface;
    @Override  
  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);  
      setContentView(R.layout.activity_main2); 
       text1 = (TextView) findViewById(R.id.text1);
        apiInterface = APIClient.getClient().create(NewApi.class);    
    Call<Library> call = apiInterface.doCreateUserWithField("your parameter"); 
       call.enqueue(new Callback<Library>() {
            @Override         
   public void onResponse(Call<Library> call, Response<Library> response) {
                Library userlist = response.body();         
       List<com.vishalsingh.retrofit.Pojo.Response> newrepo = userlist.getResponse();                String name="", address="", email="";                for (int i = 0; i <newrepo.size(); i++) {
                    name = newrepo.get(i).getName();     
               address = newrepo.get(i).getAddress();     
               email = newrepo.get(i).getEmailId();
                }
                text1.setText(name + "\n" + address + "\n" + email);            }

            @Override           
 public void onFailure(Call<Library> call, Throwable t) {
     Toast.makeText(Main2Activity.this, "cannot load data", Toast.LENGTH_SHORT).show();            }
        });    }


}
activity_main.xml

<?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=".Main2Activity">
<TextView   
 android:layout_width="match_parent"   
 android:layout_height="wrap_content"  
  android:id="@+id/text1"/>
</android.support.constraint.ConstraintLayout>


Sample json

{
"Status":true,
"Error":
{
"Code":0,
"Message":""
},
"Response":
[{"Name":"Shubham Shrivastava",
"Image":"http://103.115.194.111:906/Readers/uploads/Screenshot_20190424-202039.jpg",
"Gender":"Mr.",
"DateOfBirth":"26 Dec 2018",
"Address":"Noida",
"Country":"INDIA",
"PinCode":"485001",
"EmailId":"shri.shubham86@gmail.com",
"MobileNo":"9074762379",
"isPartner":"No",
"City":"",
"State":"Madhya Pradesh",
"Booth":"Other",
"Constituency":"Satna",
"Assembly":"Satna",
"Citizenship":null}
]
}
Note
In case of problem in pi  create network configuration xml file
and write this code

<?xml version ="1.0" encoding ="utf-8"?>
<network-security-config>  
  <domain-config cleartextTrafficPermitted="true">     
   <domain includeSubdomains="true">Your domain or IP address</domain> 
   </domain-config>
</network-security-config>

Alert Dialog Box

Alert Dialog Box Android AlertDialog   can be used to display the dialog message with OK and Cancel buttons. It can be used to inter...