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.

View Digital Signature

Our signature paper will look like below on android device.

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 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 file

Copy the below source code in 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 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.

Download the source code for Android capture digital signature

[sociallocker]Download Source Code For Signature View[/sociallocker]

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...

4 Responses

  1. Kevin Arvizu says:

    I just implemented your code, but at the moment to save the image, it doen’t save it. The code is identically as yours. Can you help me? I would appreciate it.

  2. taps says:

    I follow the instruction sir but it dosnt save too. but when i change my target sdk and mini same as your app. it was solve sir. thank a lot sir.

  3. siva sankar says:

    how to set textview of orderId in image before saving the file

Leave a Reply

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