Reputation: 67
I'm creating a web app here: ifridge.a2hosted.com
Feel free to login with:
Email: [email protected]
Password: Password101 (case sensitive)
I am currently in the process of creating an android studio application which will have the same core functionalities.
My Situation:
As it stands the website ifridge.a2hosted.com/add_remove_item.html has 2 buttons, a 'ScanIn' and a 'ScanOut'. Once clicked, a text input box appears and waits for a 13 digit number (representing a barcode) once entered and submitted, the barcode is added to the user's database. If a user is adding an item for the first time then they are prompted to enter the product's information manually by filling out 3 text boxes.
On the app, I would like the camera to open and scan the barcode, convert it to a 13 digit number and submit it without any user interaction. I'm looking for some guidance on the best method of doing this. And how best to implement the prompt if an item is unrecognised.
EDIT: I know how to convert the barcode to a number if I was just making a standard android app. What I am unclear about is how exactly to process this number in such a way that it is processed properly by the website.
Thanks in advance for your help!
Upvotes: 2
Views: 308
Reputation: 335
For talking between an app and the server, a Rest API is what I recommend. Basically it works like you normal web site. But you call it from the App and the response is JSON instead of HTML.
So far I programmed it myself (it is not hard), but there are probably ready-made libs.
Extended: This is an example of how to handle it, based on what I understood of your problem:
Your current PHP probably looks something like:
In the android case nothing really changes. When the picture was taken on your phone, display a loading circle or something and start a POST HTTP request. The request will be the same as a normal web browser does. Instead of printing out HTML to the user, you print out JSON. Your app then decides what to do next (depending on the JSON contents).
Example JSON:
{ "success":true, "was_unknown_barcode":true }
In the app check for the JSON result. If the was_unknown_barcode is set true, open another activity with your product detail form.
On how to do the post request, just google "android json post request".
Upvotes: 1