webservice with okhttp3

content_main.xml


<?xml version="1.0" encoding="utf-8"?><ScrollView 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:id="@+id/scrollview1"    android:layout_height="match_parent"    >
 <RelativeLayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_marginTop="20dp">

  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestUserName"      android:id="@+id/username"      android:paddingLeft="10dp"      android:paddingBottom="20dp" />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:layout_below="@+id/username"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestEmail"      android:id="@+id/firstname"      android:paddingLeft="10dp"      android:paddingBottom="20dp" />


  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:layout_marginTop="10dp"      android:layout_below="@+id/firstname"      android:textCursorDrawable="@null"      android:id="@+id/lastname"      android:singleLine="true"      android:hint="guestPassword"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:layout_marginTop="10dp"      android:id="@+id/registeremail"      android:layout_below="@+id/lastname"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestOtherStatus"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      android:layout_below="@+id/registeremail"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:id="@+id/activationcode"      android:layout_marginTop="10dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestPhoneNo"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      android:layout_below="@+id/activationcode"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:id="@+id/guestEnglishStatus"      android:layout_marginTop="10dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestEnglishStatus"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      android:layout_below="@+id/guestEnglishStatus"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:id="@+id/guestPayPalEmail"      android:layout_marginTop="10dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestPayPalEmail"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      android:layout_below="@+id/guestPayPalEmail"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:id="@+id/guestDebitCardNo"      android:layout_marginTop="10dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestDebitCardNo"      />
  <EditText      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:paddingLeft="10dp"      android:paddingBottom="20dp"      android:layout_below="@+id/guestDebitCardNo"      android:layout_marginLeft="20dp"      android:layout_marginRight="20dp"      android:id="@+id/guestExpDate"      android:layout_marginTop="10dp"      android:textCursorDrawable="@null"      android:singleLine="true"      android:hint="guestExpDate"      />

  <Button      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:textStyle="bold"      android:text="Send"      android:layout_below="@+id/guestExpDate"      android:id="@+id/send"      android:layout_marginBottom="20dp"      />
 </RelativeLayout>


</ScrollView>
 
 

 

MainActivity.java 



package com.beckondelve.signupparsing;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ScrollView;

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

import java.io.IOException;

import okhttp3.FormBody;
import okhttp3.RequestBody;
import okhttp3.Response;

@SuppressWarnings("ALL")
public class MainActivity extends AppCompatActivity {
    Button send;

    SavePref pref;
    EditText guestExpDate,guestDebitCardNo,guestPayPalEmail,guestEnglishStatus,guestPhoneNo            ,guestOtherStatus,guestPassword,guestEmail,guestUserName;
    String  guest_ExpDate,guest_DebitCardNo,guest_PayPalEmail,guest_EnglishStatus,guest_PhoneNo            ,guestOther_Status,guest_Password,guest_Email,guest_UserName,id;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        send =(Button)findViewById(R.id.send);


        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        guestDebitCardNo=(EditText)findViewById(R.id.guestDebitCardNo);
        guestExpDate=(EditText)findViewById(R.id.guestExpDate);
        guestPayPalEmail=(EditText)findViewById(R.id.guestPayPalEmail);
        guestEnglishStatus=(EditText)findViewById(R.id.guestEnglishStatus);


        guestPhoneNo=(EditText)findViewById(R.id.activationcode);
        guestOtherStatus=(EditText)findViewById(R.id.registeremail);

        guestPassword=(EditText)findViewById(R.id.lastname);
        guestUserName=(EditText)findViewById(R.id.firstname);
        guestEmail=(EditText)findViewById(R.id.lastname);

        send.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                GETDATA();
                LoginAPI();
            }
        });
    }
    public void GETDATA(){

        guest_Email=guestEmail.getText().toString();
        guest_DebitCardNo=guestDebitCardNo.getText().toString();
        guest_UserName=guestUserName.getText().toString();
        guest_EnglishStatus=guestEnglishStatus.getText().toString();

        guest_ExpDate=guestExpDate.getText().toString();
        guestOther_Status=guestOtherStatus.getText().toString();
        guest_Password=guestPassword.getText().toString();
        guest_PhoneNo=guestPhoneNo.getText().toString();
        guest_PayPalEmail=guestPayPalEmail.getText().toString();
    }
    private void LoginAPI()
    {

        final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);
        progressDialog.setCancelable(false);
        progressDialog.setMessage("loading...");
        progressDialog.show();

        FormBody.Builder formBuilder = new FormBody.Builder();
     formBuilder.add( AllParameters.id ,"");
        formBuilder.add( AllParameters.guestUserName ,guest_UserName);
        formBuilder.add( AllParameters.guestEmail ,guest_Email);
        formBuilder.add( AllParameters.guestPayPalEmail ,guest_PayPalEmail);
        formBuilder.add( AllParameters.guestPassword ,guest_Password);
        formBuilder.add( AllParameters.guestEnglishStatus ,guest_EnglishStatus);
        formBuilder.add( AllParameters.guestOtherStatus ,guestOther_Status);
        formBuilder.add( AllParameters.success ,"");
        formBuilder.add( AllParameters.guestExpDate ,guest_ExpDate);
        formBuilder.add( AllParameters.guestPhoneNo ,guest_PhoneNo);
        formBuilder.add( AllParameters.guestDebitCardNo ,guest_DebitCardNo);

        RequestBody requestBody = formBuilder.build();
        GetAsyncPost mAsync = new GetAsyncPost(this, API.guest_signupname, requestBody)
        {
            @Override            public void getValueParse(Response result)
            {
                progressDialog.dismiss();
                String response="";
                try {

                    response   = result.body().string();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                JSONObject jsonObject = null;
                try                {
                    jsonObject = new JSONObject(response);
                    Log.e("response", " : "+response);

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

                if(result.isSuccessful())
                {
                    try {
                        pref = new SavePref(MainActivity.this);

                        pref.setid(jsonObject.getString("id"));

//                        pref.setEmail(jsonObject.getString("email"));//                        pref.setFirstName(jsonObject.getString("firstname"));//                        pref.setLastName(jsonObject.getString("lastname"));////                        pref.setUSERNAME(jsonObject.getString("username"));                        Intent i = new Intent(MainActivity.this,Login.class);
                        startActivity(i);
                        finish();

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

                }else{
                    try {
                        Util.showToast(MainActivity.this,jsonObject.getString("message"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override            public void retry()
            {

            }
        };
        mAsync.execute();
    }


}
Allparameters.java
 
 
package com.beckondelve.signupparsing;

/** * Created by android3 on 29/7/17. */public class AllParameters {
    public static String id = "id";
    public static String guestUserName = "guestUserName";
    public static String guestEmail = " guestEmail";
    public static String guestPassword = " guestPassword";
    public static String guestOtherStatus="guestOtherStatus";
    public static String guestPhoneNo="guestPhoneNo";
    public static String guestEnglishStatus="guestEnglishStatus";

    public static String guestPayPalEmail = " guestPayPalEmail";
    public static String guestDebitCardNo="guestDebitCardNo";
    public static String success="success";
    public static String guestExpDate="guestExpDate";


}
 
 
API.java
 
 
package com.beckondelve.signupparsing;

/** * Created by android3 on 29/7/17. */public class API

{
    public static String BASE_URL =  "https://allappshere.in/porter/index.php?action=";

    public static String guest_signupname = BASE_URL + "guest_signup&name=%@&email=%@&phoneno=%@&spkenglish=%@&othenglish=%@&paypalemail=%@&debitcardno=%@&expdate=%@&guestDeviceToken=%@&password=%@&guestUniqueCode=%@";


}
 
 
GetAsynPost.java
 
 
package com.beckondelve.signupparsing;

/** * Created by android3 on 29/7/17. */import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Build;
import android.support.v7.app.AlertDialog;

import java.lang.ref.WeakReference;
import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public abstract class GetAsyncPost extends AsyncTask<Response, Void, Response>
{

    String url = "";
    RequestBody requestBody;
    Context context;
    WeakReference<Context> contextWeakReference;
    AlertDialog.Builder builder;
    SavePref SavePref;

    public GetAsyncPost(Context context, String url, RequestBody requestBody)
    {
        this.url = url;
        this.requestBody = requestBody;
        contextWeakReference = new WeakReference<Context>(context);
        this.context = contextWeakReference.get();
    }

    @Override    protected void onPreExecute()
    {
        super.onPreExecute();
        SavePref =new SavePref(context);
    }

    @Override    protected Response doInBackground(Response... params) {
        Response jsonData = null;
        try {
            try {
                OkHttpClient client = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS)
                        .readTimeout(30, TimeUnit.SECONDS)
                        .build();

                Request request = new Request.Builder().post(requestBody)
                        .url(url)
                        .build();

                try                {
                    Response responses = client.newCall(request).execute();
                    jsonData = responses;
//                    jsonData = responses.body().string();                }
                catch (SocketTimeoutException ex)
                {
                    showDialog();
                }
                catch (ConnectException ex)
                {
                    showDialog();
                }
                catch (Exception ex)
                {
                    ex.printStackTrace();
                }
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonData;
    }

    @Override    protected void onPostExecute(Response result)
    {
        super.onPostExecute(result);
        if (result != null) getValueParse(result);
    }

    public abstract void getValueParse(Response listValue);

    public abstract void retry();

    private void showDialog() {

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        {
            builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
        }
        else        {
            builder = new AlertDialog.Builder(context);
        }
        builder.setTitle("Warning!");
        builder.setMessage("internet error");
        builder.setCancelable(true);

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                retry();
            }
        });

        ((Activity) context).runOnUiThread(new Runnable() {
            public void run() {
                AlertDialog alert11 = builder.create();
                alert11.show();
            }
        });

    }
}
 
 
SavePref.java
 
 
 
package com.beckondelve.signupparsing;

/** * Created by android3 on 29/7/17. */import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;


public class SavePref {
    public static final String TAG = "SavePref";
    Context context;
    public static final String PREF_TOKEN = "AddChatToken";
    SharedPreferences preferences;
    static SharedPreferences.Editor editor;

    public SavePref(Context c) {
        context = c;
        preferences = PreferenceManager.getDefaultSharedPreferences(context);
        editor = preferences.edit();
    }

    public void setmobile(String mobileno) {
        editor.putString("mobileno", mobileno);
        editor.commit();
    }
    public void setauthorization_key(String authorization_key) {
        editor.putString("authorization_key", authorization_key);
        editor.commit();
    }

    public void setOTP(String otp) {
        editor.putString("otp", otp);
        editor.commit();
    }
    public void  setcountry_code(String country_code) {
        editor.putString("country_code", country_code);
        editor.commit();
    }

    public String getOTP() {
        String name = preferences.getString("otp", "");
        return name;
    }
    public void  setFirstName(String firstname) {
        editor.putString("firstname", firstname);
        editor.commit();
    }

    public String getFirstName() {
        String firstname = preferences.getString("firstname", "");
        return firstname;
    }
    public void  setLastName(String lastname) {
        editor.putString("lastname", lastname);
        editor.commit();
    }

    public String getLastName() {
        String lastname = preferences.getString("lastname", "");
        return lastname;
    }
    public void  setPassword(String password) {
        editor.putString("password", password);
        editor.commit();
    }

    public String getPassword() {
        String password = preferences.getString("password", "");
        return password;
    }
    public void  setImage(String image) {
        editor.putString("image", image);
        editor.commit();
    }

    public String getImage() {
        String image = preferences.getString("image", "");
        return image;
    }
    public void  setgender(String gender) {
        editor.putString("gender", gender);
        editor.commit();
    }

    public String getgender() {
        String gender = preferences.getString("gender", "");
        return gender;
    }
    public void  setDOB(String dob) {
        editor.putString("dob", dob);
        editor.commit();
    }

    public String getDOB() {
        String dob = preferences.getString("dob", "");
        return dob;
    }
    public void  setis_verified(String is_verified) {
        editor.putString("is_verified", is_verified);
        editor.commit();
    }

    public String getis_verified() {
        String is_verified = preferences.getString("is_verified", "");
        return is_verified;
    }
    public void  setnumbertype(String numbertype) {
        editor.putString("numbertype", numbertype);
        editor.commit();
    }

    public String getnumbertype() {
        String numbertype = preferences.getString("numbertype", "");
        return numbertype;
    }
    public void  setassigned_business(String assigned_business) {
        editor.putString("assigned_business", assigned_business);
        editor.commit();
    }

    public String getassigned_business() {
        String assigned_business = preferences.getString("assigned_business", "");
        return assigned_business;
    }

    public void  setstatus(String status) {
        editor.putString("status", status);
        editor.commit();
    }

    public String getstatus() {
        String status = preferences.getString("status", "");
        return status;
    }
    public void  setsidebar_rollup(String sidebar_rollup) {
        editor.putString("sidebar_rollup", sidebar_rollup);
        editor.commit();
    }

    public String getsidebar_rollup() {
        String sidebar_rollup = preferences.getString("sidebar_rollup", "");
        return sidebar_rollup;
    }
    public void  setgroup_id(String group_id) {
        editor.putString("group_id", group_id);
        editor.commit();
    }

    public String getid() {
        String id = preferences.getString("id", "");
        return id;
    }
    public void  setid(String id) {
        editor.putString("id", id);
        editor.commit();
    }

    public String getcreated() {
        String created = preferences.getString("created", "");
        return created;
    }
    public void  setmodified(String modified) {
        editor.putString("created", modified);
        editor.commit();
    }

    public String getmodified() {
        String modified = preferences.getString("modified", "");
        return modified;
    }



    public void  setDBID(String db_id) {
        editor.putString("db_id", db_id);
        editor.commit();
    }

    public String getDBID() {
        String db_id = preferences.getString("db_id", "");
        return db_id;
    }

    public void  setEmail(String email) {
        editor.putString("email", email);
        editor.commit();
    }

    public String getEmail() {
        String email = preferences.getString("email", "");
        return email;
    }
    public void  setAppKey(String appkey) {
        editor.putString("app-key",  appkey);
        editor.commit();
    }
    public String getAppKey() {
        String appkey = preferences.getString("app-key", "");
        return appkey;
    }
    public void  setAKey(String akey) {
        editor.putString("akey",  akey);
        editor.commit();
    }
    public String getAKey() {
        String akey = preferences.getString("akey", "");
        return akey;
    }
    public void  setUSERNAME(String username) {
        editor.putString("username",  username);
        editor.commit();
    }
    public String getUSERNAME() {
        String username = preferences.getString("username", "");
        return username;
    }


    public String getLoginType() {
        String name = preferences.getString("EnterProfileActivity", "");
        return name;
    }

    public void clearPreferences() {
        preferences.edit().clear().commit();
    }
}
 
 
Util.java
 
 
package com.beckondelve.signupparsing;



import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ProgressDialog;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Color;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Util
{

    private static Util ourInstance = new Util();
    public static String Appkey="923874926426775421669845";
    public static String Internet_Check = "Please Check Your Internet Check Connection";


    public static synchronized Util getInstance() {
        return ourInstance;
    }

    private Util() {
    }

    public static void showToast(Context context, String message) {
        Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }



    public static String internet_Connection_Error = "Please Check Your Internet Connection";
    public static String message = "";

    public static void hideKeyboard(Activity context)
    {
        View view = context.getCurrentFocus();
        if (view != null) {
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    }

    private void internet(Activity context) {
        Util.getInstance().showToast(context, Util.internet_Connection_Error);
    }

    public static ProgressDialog initializeProgress(Context context) {
        ProgressDialog progressDialog = new ProgressDialog(context);
        progressDialog.setCancelable(false);
        progressDialog.setMessage(context.getResources().getString(R.string.loading));
        return progressDialog;
    }
    public static boolean isValidEmail(String email) {
        String EMAIL_PATTERN = "[a-zA-Z0-9\\+\\.\\_\\%\\-\\+]{1,256}" +
                "\\@" +
                "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,64}" +
                "(" +
                "\\." +
                "[a-zA-Z0-9][a-zA-Z0-9\\-]{0,25}" +
                ")+";

        Pattern pattern = Pattern.compile(EMAIL_PATTERN);
        Matcher matcher = pattern.matcher(email);
        return matcher.matches();
    }

    @SuppressLint("NewApi")
    public static String getPath(final Context context, final Uri uri)
    {
        final boolean isKitKatOrAbove = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

        // DocumentProvider        if (isKitKatOrAbove && DocumentsContract.isDocumentUri(context, uri)) {
            // ExternalStorageProvider            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }

                // TODO handle non-primary volumes            }
            // DownloadsProvider            else if (isDownloadsDocument(uri)) {

                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video1".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[]{
                        split[1]
                };

                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)        else if ("content".equalsIgnoreCase(uri.getScheme())) {
            return getDataColumn(context, uri, null, null);
        }
        // File        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }
        return null;
    }

    /**     * Get the value of the data column for this Uri. This is useful for     * MediaStore Uris, and other file-based ContentProviders.     *     * @param context       The context.     * @param uri           The Uri to query.     * @param selection     (Optional) Filter used in the query.     * @param selectionArgs (Optional) Selection arguments used in the query.     * @return The value of the _data column, which is typically a file path.     */    public static String getDataColumn(Context context, Uri uri, String selection,
                                       String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                final int column_index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(column_index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }


    /**     * @param uri The Uri to check.     * @return Whether the Uri authority is ExternalStorageProvider.     */    public static boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

    /**     * @param uri The Uri to check.     * @return Whether the Uri authority is DownloadsProvider.     */    public static boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }

    /**     * @param uri The Uri to check.     * @return Whether the Uri authority is MediaProvider.     */    public static boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }

    public static boolean isNetworkAvailable(Context context)
    {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }


    public static boolean isMyServiceRunning(Class<?> serviceClass, Context context) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceClass.getName().equals(service.service.getClassName())) {
                return true;
            }
        }
        return false;
    }

}
 
 
Manifest
 
 
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.beckondelve.signupparsing">

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

    <application        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"            android:label="@string/app_name"            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity            android:name=".Login"            android:label="login"            android:theme="@style/AppTheme" >

        </activity>
        <activity            android:name=".bottomNavigation"            android:label="@string/title_activity_bottom_navigation"></activity>
        <activity            android:name=".Main2Activity"            android:label="@string/title_activity_main2"            android:theme="@style/AppTheme.NoActionBar">

        </activity>
    </application>

</manifest>
 
 
 
Gradle
 
apply plugin: 'com.android.application'
android {
    compileSdkVersion 26    buildToolsVersion "26.0.1"    defaultConfig {
        applicationId "com.beckondelve.signupparsing"        minSdkVersion 15        targetSdkVersion 26        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"        vectorDrawables.useSupportLibrary = true    }
    buildTypes {
        release {
            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'    })

    compile 'com.android.support:appcompat-v7:26.+'    compile 'com.android.support.constraint:constraint-layout:1.0.2'    compile 'com.android.support:design:26.+'    compile 'com.squareup.okhttp3:okhttp:3.6.0'    compile 'com.google.code.gson:gson:2.2.4'    compile 'com.android.support:support-vector-drawable:26.+'    testCompile 'junit:junit:4.12'}
 

Comments