Implementing Google Forms To Android Application

In this article, we will see how to create a simple feedback system using Google Forms in the back-end. For online applications, we have a separate table for feedback from users. But, for offline applications like music player, we will not connect any databases like MySQL, SQL Server or any. We need to build the same with Firebase Real-time Databases also.

Google Forms To Android Application
Introduction

In this article, we will see how to create a simple feedback system using Google Forms in the back-end. For online applications, we have a separate table for feedback from users. But, for offline applications like music player, we do not connect any databases like MySQL, SQL Server etc. We need to build the same with Firebase Real-time Databases also.

Pros of using Google Forms

  1. It provides a real-time user-friendly response
  2. Cost Free
  3. Easy to Integrate.

Coding Part

I have split this write-up into 3 steps as in the following.

  • Step 1- Creating a new project with Empty Activity.
  • Step 2- Setting up the HTTP Library.
  • Step 3- Creating Google Forms.
  • Step 4- Implementation of Google Forms Backend.

Step 1 - Creating a new project with Android Studio

  1. Open Android Studio and select "Create New Project".
  2. Name the project as per your wish and select your activity template.

    Google Forms To Android Application

  3. Click finish button to create a new project in Android Studio.

Step 2 - Setting up the Firebase Library

In this part, we will see how to set up the library for the project.

  1. Then, add the following lines in the app level build.gradle file to apply Google Services to your project.
    1. dependencies {  
    2.    ...  
    3.    implementation 'com.android.volley:volley:1.1.1'  
    4. }  
  1. Then, click Sync Now to set up your project.

Step 3 - Creating Google Forms

  1. The first thing you need to do is to log in to google.com and create a new “Google Form”.
  2. After creating your Google Form, get your share link from the Forms.

    For Example
    Your link looks like below,

    https://docs.google.com/forms/d/e/1FAIpQLScIpmqndQeQG3lFbj0QkQ1Kt6tEXoPrOt314AZGQ2WKuK8IvA/viewform
  1. Your shareable link should be converted for posting data to Google Forms. The conversion is very easy. It is just to replace “viewform” in the shareable link to “formResponse”.

    For Example
    After your link will be shown below,

    https://docs.google.com/forms/d/e/1FAIpQLScIpmqndQeQG3lFbj0QkQ1Kt6tEXoPrOt314AZGQ2WKuK8IvA/formResponse
  1. The tricky part of using Google Forms as Backend is, we have to make a POST request with Key-Value Pair. Values to be posted from the application uses the keys which are to be the IDs of the input fields of Google Forms.

  2. To get the keys of the input fields in the Google Forms, right click on the textbox and select “Inspect Element”. Take field’s name from the form which looks like 7374858782.

    Google Forms To Android Application

Step 4 - Implementation of Google Forms as Backend

  1. Here, I have used Volley as my HTTP library to make POST request.
  2. Don’t forget to add Internet Permission in AndroidManifest.xml.
  3. Here, I used StringRequest in Volley. The following code will show how the data to be posted to Google Forms.
    1. public void postData(final String name, final String phone) {  
    2.     StringRequest request = new StringRequest(  
    3.             Request.Method.POST,  
    4.             Constants.url,  
    5.             new Response.Listener<String>() {  
    6.                 @Override  
    7.                 public void onResponse(String response) {  
    8.                     Log.d("TAG""Response: " + response);  
    9.                     if (response.length() > 0) {  
    10.                         Snackbar.make(fab,"Successfully Posted", Snackbar.LENGTH_LONG).show();  
    11.                         edtName.setText(null);  
    12.                         edtPhone.setText(null);  
    13.                     } else {  
    14.                         Snackbar.make(fab, "Try Again", Snackbar.LENGTH_LONG).show();  
    15.                     }  
    16.                     progressDialog.dismiss();  
    17.                 }  
    18.             }, new Response.ErrorListener() {  
    19.   
    20.         @Override  
    21.         public void onErrorResponse(VolleyError error) {  
    22.             progressDialog.dismiss();  
    23.             Snackbar.make(fab, "Error while Posting Data", Snackbar.LENGTH_LONG).show();  
    24.         }  
    25.     }) {  
    26.         @Override  
    27.         protected Map<String, String> getParams() {  
    28.             Map<String, String> params = new HashMap<>();  
    29.             params.put(Constants.nameField, name);  
    30.             params.put(Constants.phoneField, phone);  
    31.             return params;  
    32.         }  
    33.     };  
    34.     request.setRetryPolicy(new DefaultRetryPolicy(  
    35.             50000,  
    36.             DefaultRetryPolicy.DEFAULT_MAX_RETRIES,  
    37.             DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));  
    38.     queue.add(request);  
    39. }  
  1. You can view the responses in Google form's Response section or in Google sheets. To get response in Google sheet, just click excel symbol in response section of your Google form.

You can read the same on my blog here.

Download Code

You can download the full source code of the article in GitHub. If you like this article, do star the repo in GitHub. Hit like the article.