Retrieve data from a web server for android application - android

I am developing an application that needs to retrieve some data from a web server. But I have no idea how can this be possible?

You need to create what is called a web service. This web service acts as a web page that can be read easily by machines. This page will let your program make HTTP posts and gets (Just like a web browser) in order to request and receive information. You can look at this page for the Google Maps API to see an example of how it works.
For the protocol that you use to communicate, you have many options. Among the most popular are JSON and XML.
To create the web service itself you have a multitude of options. It seems to be Java Servlet s and PHP are popular, but there are many others (ASP, Perl, Python ...).

Related

Can I use Ruby on Rails as a native Android backend?

I have a web application developed with RoR, and I was wondering if it was plausible to use it as the backend for an Android application that I would develop in Java or Kotlin?
For example, if the web applications authentication is handled with devise, can I get the Android application to send the name and password to my web application and have it return the user as a JSON?
Absolutely you can.
Usually the Android app would call an API rather than a web page. That is you don't exchange HTML like a browser does, just the essential JSON. Lots of things work the same as a web site. For example you can use the same authentication mechanism for the API as for the web-site.
This is a good starting point for RoR to create an API.
https://guides.rubyonrails.org/api_app.html
Here's a starter for Android making a web-service call:
https://developer.android.com/training/volley/simple
That's just a get, which you might use to get a list of something that's publicly available. It's probably worth understanding the other pages just there because with web calls it's really easy to do bad things like lock up the UI thread, so best to use the example patterns and methods.

Allow to open website on webview only

I want to ask about the security of web application.
I'm developing on web site for an inventory management system by web service.
And wrapping as android application with the webview.
But my client ask the website can be opened in android application only.
I think it is possible with agent header when web server response to request.
But it just a makeshift.
So is there any way to check the website is opened in browser not authorized application?
I used spring boot for web server.
This is not possible. Once you expose an endpoint publicly, you can always try to connect to it with whatever software supporting the protocol (or an analyzer which will reverse-engineer the protocol).
This said, you can make it difficult by obfuscation.
One solution is to use information provided by the client (browser in your case). This is usually the agent header (as you mention) but can also be some fingerprinting. You could for instance detect the size of the screen and make some decisions from there on.
Another solution is to use some secrets (better call them "secrets") to show the backend application (or API) that some specific code is calling. I can imagine that you could bundle the HTML/JS/CSS code in your application, together with a key so only the application owners will be able to send a recognizable traffic (recognized by the backednd).
All of this is more or less difficult to crack but with some layers you will get rid of at least some population which would like to access the site via other means than an app.

How to feed data to a mobile app for a website

There are various websites (say LinkedIn) which have a corresponding mobile app.My question is - "How they feed data to their mobile apps?". Obviously they are not doing HTML scraping of their webpages, otherwise it would be really inefficient.
I am asking this because I have a website, and I am also going to develop an android app for that.So, do I have to design my website (like database) in a specific way to support mobile apps. (I mean, what are the preconditions do I take care of , while designing my website, in relation to the mobile apps)
What you need is a web service. It sounds little complicated but actually its not! in normal websites when you visit a website you get HTML data. but in web service when you request for a data you get the data in xml or json. Then on client side you parse this data and show it as you like.
The most used method for sending data between web services and clients is called RESTful web service and it usually uses json. So after a request you get a .json file. I highly recommend you to use RESTful web service especially since you are a beginner.
As i said RESTful web services are famous so most frameworks support that! So if you are creating you website with this frameworks you don't have to code anything! they build the web service for you. If not there are plenty of code for any given language.
Another thing is since xml (and json) file are platform independent you only need one web service to handle all of the client (android, ios, windows, etc.). And there are sufficient tools and libraries in each platform to work with xml (json) files. Sending data to server is also the same, you send the data in xml format, service receive it and do what ever need to be done (for example stores the data in database)
Lastly the world of web services are a lot bigger. What i said was a highly simplified version to give you a whole idea! If you interested to learn more there are plenty of books you can read. Many people (including myself) think web services are the future of internet. Where different services each developed by different company work together to provide user with something great.

Service to connect to SQL Server with Android

I'm creating my first android app. My app works in the following way:
User log into the app.
The login details is on an online server which is SQL Server 2008 R2
The server will return data to the app and the data the data will be stored on the app's database.
The problem I am facing is how should i connect to Sql server database. I researched on this topic and found out that I need to use some service. Can someone suggest as to what service should i use? A normal .NET web service, WCF service or Java Service.
I also need to know how to consume this service in my app.
Softwares I have with me:
Visual Studio 2008
SQL Server 2008 R2.
Android Development Kit & Eclipse
SQLite
Please help me.
I highly recommend the Asp.Net Web API for this:
"ASP.NET includes ASP.NET Web API for creating rich REST-ful Web Services that return JSON, XML, or any kind of content the web supports! ASP.NET Web APIs can provide data services to mobile apps like Windows Phones, iPhones, Android and more. ASP.NET Web APIs can be used in any ASP.NET Web Application, including ASP.NET MVC, Web Forms, or Web Pages – it's all One ASP.NET."
http://www.asp.net/web-api
Just to get you the general overview here;
You do not connect your (Android) app directly to the remote SQL database/server. Android, nor any other mobile platform, provides a steady and reliable interface for doing so.
Secondly, what you want to make indeed is a (REST) web-service.
As long as your needs are simple (passing along a bit of simple data between your app and your database) this means nothing more then having some web language take up some GET or POST variables and putting them in the database for you. And the same the other way around.
You can do this in any (web)language. The choice for language might be most influenced by the server you want to run in on, and what languages it already supports.

Architecture for Android app using GWT

I need to build Android application using Java which is able to send request to read or write some data to "database" or similar data store on google web server (using GWT technology).
Android app should be able to authenticate user with Google Account, send request to server to add data to database on server, receive data form server.
I would like to know what is the best approach and architecture I should use? What mechanism should I use to get data response over network (RPC, GET request)? What should I put on server side (servlet, ...) ?
There is example how to build gwt app: which run 1. javascript in browser 2. servlet, service, serviceImpl, serviceAcynch, etc... I think this is no use for my app because I need to directly get and send data to/from server.
I need to have data exchange with GWT server to get/update coordinates for my Google MapView. Therefore I need to use data exchange mechanism between android client app and GWT.
Why do I need this on android? I have to be able to get GPS position of android device and update data with web server, then display my android device position on map. I need GWT to store, put, return position data (for example to show visited locations). Should it be build as Android native app? How can I update, get data from GWT server?
You've asked a general question. The best I can do is give you a general answer. For stuff like this, I like to build up a REST framework. REST is a robust and resilient paradigm which is something you need when developing mobile applications, the network connection could go out at any time. Using REST, you can just use standard HttpRequests to query the server. Responding to the requests server side is as simple as processing the HttpRequests. On Android, the HttpURLConnection class is perfect for this kind of stuff. If you want a rather complex but comprehensive example of all this, you can take a look at the SampleSyncAdapter example in the android SDK. Also, you might find this Google IO video interesting. It's one of my favorites.

Categories

Resources