Step 1: Create new app script project. Click here to create App Script.
Step 2: Copy and paste the below script which recieves scanned data and inserts in Google Sheet.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
function doGet(e){
var ss = SpreadsheetApp.openByUrl("Your Spread Sheet URL");
var sheet = ss.getSheetByName("Sheet1");
return insert(e,sheet);
}
function doPost(e){
var ss = SpreadsheetApp.openByUrl("Your Spread Sheet URL");
var sheet = ss.getSheetByName("Sheet1");
return insert(e,sheet);
}
function insert(e,sheet) {
var scannedData = e.parameter.sdata;
var d = new Date();
var ctime = d.toLocaleString();
sheet.appendRow([scannedData,ctime]);
return ContentService
.createTextOutput("Success")
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
|
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.
activity_main.xml This adds a button to Scan
Step 4: add the following code to MainActivity.java which scans and calls web service
ليست هناك تعليقات:
إرسال تعليق