Google Sheet As DATABASE for your Android Application Part – 3 | [CRUD] Create, Read, Update, Delete operation on Google Sheets from Android App

Previously I have posted about Insert and Fetching data from Google Sheet to Android app. So here I am covering complete CRUD operation in a single App so that it can be helpful for those who need it completely.

I recommend using this code to everyone instead of Part-1 and Part -2,

 

Here It consists of 2 Parts,

  1. Google App Script Part (Back End)
  2. Android Part (Front End)

Source Code

 

1.Google App Script Part

Step 1 : Create new app script project. Click here to create App Script.

Step 2 : Copy and paste the below script which handles two attributes (id,name). You can change the logic, attributes as required.

 

Step 3: Change the url of the spread sheet. Make sure sheet is shared .[anyone with the link can view]

Step 4: Go to Publish -> Deploy as web app. A window pop up, here ->Who has access to the app: ->  Anyone, even Anonymous

Publish/Update. Copy the published URL and store it.

 

 

2. Android Part

Step 1: Create new Android App from Android Studio

Step 2: Go to build.gradle[module: app] and add following dependencies.

note: If you are downloading the source code and modifying. Please make sure build tool version and compileSdk Version in build.gradle[module: dependancyapp] are compatible with your phone. If you are developing from the scratch then no issues, just dependency,

Step 3: Let’s add all layout files.

 

  1. activity_main.xml  This holds the button of CRUD operation.

     
  2. insert_data.xml  This Contains the View of 2 Text fields and Insert Button

     
  3. read_data.xml

     
  4. update_data.xml

     
  5. delete_data,xml

     
  6. read_all.xml

     
  7. layout_row_view.xml

     

Step 4 : Now Let’s Add Java Class Files Which handles and Controles the operation.

 

1 Controller.java

2. InsertData.java

 

3. ReadSingleData.java

4. UpdateData.java

5. DeleteData.java

Step 4: To View All the data I am using Array Adapter and list

1 MyArrayAdapter.java

2.MyDataModel.java

3.ReadAllData.java

Step 5 : Add MainActivity.java

Step 6 : Change Manifest.xml file

 

Now Run The Code

 

Source Code