Android Capture Digital Signature And Save In Android Studio

I will make Android capture digital signature tutorial with example in this article.

You will learn how to get and save human digital signature in android studio.

After drawing and making the digital signature, we will also save it in the image format.

Digital Signature

Digital Signature capture is a technique for signing electronic document files with a handwritten signature.

It holds the equal importance as of the paper signature.

Digital Signature pad is useful when you want to get real signature from human on android device.

For example, courier person use this technique most effectively. You can also use this feature in an online registration platform and information gathering systems.

It saves paper and you also do not need to maintain every single paper for every individual.

Signatures of all persons is saved in one single device so it is easy to store and for transportation.

Step 1. Integrating Library

  • We will use SignatureView Library to accomplish our task.
  • Write down the following line in your build.gradle(Module: app) file.

  • Above line will download all the necessary files which are required to create signature view in xml layout file.

Step 2. Permissions

We are going to save the human digital signature in an image format. For this task, we have to define following two permissions in AndroidManifest.xml file

  • Note : I am targeting the sdk version 22 here so I do not need to check for runtime permissions.
  • If you are targeting sdk version greater than 22 then you need to request runtime permissions.

Step 3. Last Edits

  • Now all we need is to write some source code in activity_main.xml and MainActivity.java file.

Add the below source code in activity_main.xml file

  • In the main layout structure, I have added one signature view. It will create a white space on which user can write his signature.

Then I have added two buttons.

  • One button will clear the signature view when you click it.
  • Other one will save the image of the digital signature view.

Now it’s time to write the MainActivity.java file

Copy the below source code in MainActivity.java file

Diving Deep

After implementing library, we are able to generate a signature view like ImageView as we have already added it in activity_main.xml

In MainActivity.java file, I have made an object of it using findViewById().

Consider below code

  • Here I have created necessary objects.
  • IMAGE_DIRECTORY HOLDS THE FOLDER NAME where the image will be generated.

Look at the below source code

  • Compiler will run this code when the user clicks clear button.
  • This will clear the signature view means that any existing writings will be erased from the signature pad.

  • When the user clicks the save button, compiler will execute the above code.
  • It will save the existing writings of signature view in an image format.

For creating the image of the signature, we need to have bitmap.

Following line will give us bitmap.

We will use this bitmap to save the image.

Below line will save the image.

  • Here, I have used saveImage() method to create the image. After creating the image, this method will return path of the saved image in string format.
  • path (String variable) will hold the image path returned by the saveImage() method.

Code for saveImage() method is as per following

  • This method will save the image from the bitmap.
  • This method uses IMAGE_DIRECTORY (string variable which holds the folder name), to create the image path.

Change it’s value to create the folder of your choice.

If you do not want to use third party library then you can use canvas class to create signature view.

Read Android Signature With Canvas Tutorial With Example for this purpose.

View Digital Signature

Our signature paper will look like below on android device.

Download the source code for Android capture digital signature

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *