Posts

EasyPermission Library

Image
In this tutorial,we will learn, how to use the EasyPermissions library to request a dangerous permission at run time, which is necessary since Android Marshmallow (API level 23). This library provides an easy way to request multiple permissions at once, handle the results (granted or denied), show a rationale when the user previously denied a permission with an explanation of why this permission is needed and it even provides an easy way to create an AlertDialog that sends the user directly to the settings of the phone to manually grant a permission if he previously checked the “don’t ask again” box. In MainActivity.java class file add these lies of codes:- package com.deftskill.easypermissionexample; import androidx.annotation. NonNull ; import androidx.appcompat.app.AppCompatActivity; import android.Manifest; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.util.List; import pub.d...

Validate Email & Password with Regular Expression

Image
  In this video we will learn, how to validate an email address and password client side, by using regular expressions (regex). This way we can check, if the inserted email address is formed like an email address, and if the password contains certain characters, like upper and lower case letters, digits and special characters. For this we will use the Pattern class, with which we can compile a regex from a string and then use the matcher method to compare it with the input. In build.gradle file add this dependency:- implementation 'com.google.android.material:material:1.0.0' In MainActivity.java class file add these lines of codes:- import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.util.Patterns; import android.view.View; import android.widget.Toast; import com.google.android.material.textfield.TextInputLayout; import java.util.regex.Pattern; public class MainActivity extends AppCompatActivity { private static final Pattern PASSWORD_P...

UPI Payment Integration Android

Image
                                 In this tutorial we will learn how to integrate upi payment gateway in our app. In gradle file add this dependency:- // EasyUpiPayment Library implementation 'com.shreyaspatil:EasyUpiPayment:3.0.0' Note:- Minimum Sdk must not be below 19 In MainActivity.java class file add these lines of codes:- package com.deftskill.upiintegration; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Toast; import com.shreyaspatil.easyupipayment.EasyUpiPayment; import com.shreyaspatil.easyupipayment.listener.PaymentStatusListener; import com.shreyaspatil.easyupipayment.model.PaymentApp; import com.shreyaspatil.easyupipayment.model.TransactionDetails; import java.util.ArrayList; public class MainActivity extends AppCompatActivity implements PaymentStatusListener {     private EasyUpiPayment easyUpiPayment; ...

How to Restore Variable when the Device is Rotated

Image
When there are runtime configuration changes in your Android phone, like changing the screen orientation or the device’s language, your whole app process will be destroyed and recreated from scratch and together with it, all member variables will be reset. The system already takes care of default views like the text in an EditText field or the scrolling position of a RecyclerView or ListView. But we have to restore the variables of our activity ourselves and we do this by overriding onSaveInstanceState and passing the values to the outState Bundle. After the Activity has been recreated, there are 2 places where we can get our values back: onCreate or onRestoreInstanceState, which both get passed the savedInstanceState Bundle. In MainActivity.class file add these lines of codes:- public class MainActivity extends AppCompatActivity { private TextView mTextViewCount ; private int mCount ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreat...

AsyncTask+Weakreference

Image
                                                              In this Tutorial we will learn, how to use the AsyncTask class, which makes it easier to do operations on a background thread and publish the results on the UI/main thread, without having to manipulate threads and handlers ourselves. For this we will subclass Asynctask, define 3 generic types for the params, the progress and the result and override 4 methods: onPreExecute, where we do preparations on the UI thread, doInBackground where we do the heavy work on a background thread, onProgressUpdate where we publish the progress to the UI thread (for example to a ProgressBar), and onPostExecute where we get back the result from the background task. In order to not leak memory by holding onto a strong reference to our MainActivity, we will make the AsyncTask static and keep a W...

Modal Bottom Sheet

Image
In this tutorial we will learn, how to create a modal bottom sheet, by subclassing BottomSheetDialogFragment. Our sheet will have a custom layout and it will be able to communicate back to the underlying activity over an interface. In Main.Activity.java class file add these lines of codes:- import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity implements ExampleBottomSheetDialog.BottomSheetListener{ private TextView mTextView ; @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout. activity_main ); mTextView = findViewById(R.id. text_view_button_clicked ); Button buttonOpenBottomSheet = findViewById(R.id. button_open_bottom_sheet ); buttonOpenBottomSheet.setOnClickListener( new View.OnClickListener() { ...