How to sync a Google spreadsheet in an Android application and read rows from it

I have one spreadsheet file in my Google Drive that I want to sync with an Android app. After successful synchronization, I have some search criteria in my applications, I want to get results based on these criteria from the file that I am synchronizing. I am doing this for the first time and am not getting good resources to start with.

1) How to sync Google Drive file in Android app?

2) How to get data from a table that I synchronized?

Note I am also confused between the Google Docs API and the Google Drive SDK .

What to use in my application?

I have only one file to sync every time, and not all files. And the file is open to everyone with a private key.

I have implemented some code, but it does not work. Below is my shared spreadsheet address that I want to sync in my Android app.

I follow the steps from here .

My test spreadsheet url

try { String USERNAME = "xxxxx"; String PASSWORD = "xxxxx"; SpreadsheetService service = new SpreadsheetService("Testing"); service.setUserCredentials(USERNAME, PASSWORD); // TODO: Authorize the service object for a specific user (see other sections) // Define the URL to request. This should never change. URL SPREADSHEET_FEED_URL = new URL( "https://spreadsheets.google.com/feeds/spreadsheets/private/full"); // Make a request to the API and get all spreadsheets. SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class); List<SpreadsheetEntry> spreadsheets = feed.getEntries(); if (spreadsheets.size() == 0) { // TODO: There were no spreadsheets, act accordingly. } // TODO: Choose a spreadsheet more intelligently based on your // app needs. SpreadsheetEntry spreadsheet = spreadsheets.get(0); System.out.println(spreadsheet.getTitle().getPlainText()); // Make a request to the API to fetch information about all // worksheets in the spreadsheet. List<WorksheetEntry> worksheets = spreadsheet.getWorksheets(); // Iterate through each worksheet in the spreadsheet. for (WorksheetEntry worksheet : worksheets) { // Get the worksheet title, row count, and column count. String title = worksheet.getTitle().getPlainText(); int rowCount = worksheet.getRowCount(); int colCount = worksheet.getColCount(); // Print the fetched information to the screen for this worksheet. System.out.println("\t" + title + "- rows:" + rowCount + " cols: " + colCount); } } catch (Exception e) { e.printStackTrace(); } 
+4
source share
1 answer

I understood. I did not add permission, and that is why it gives me an error. We need to add permission for authorization.

 <uses-permission android:name="android.permission.ACCOUNT_MANAGER" /> <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" /> 
+3
source

Source: https://habr.com/ru/post/1433516/


All Articles