Android - Rails communication - android

Given the lack of information on the web ask a question:
I'm going to create an application in Android, the use of a database application
Rails. For this I need a manual session. So if anyone has a ready
example / tutorial showing communication android-rails using
session, or is able to share your knowledge on this subject?

Rails 3 resources use RESTful APIs by default. Define a supported format (XML or JSON) in your Rails app and just make REST calls from your Android client.
There should be no need for you to be trying to manipulate the database directly from your Android client. That will skip all the validations and before_saves you have set up in your Rails app.
Use REST and you should be fine.

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.

Can I use ASP MVC Web App To return JSON instead of Web API to an Android App?

I already have an ASP MVC web application with authentication and authorization.
and now I am working on an android application which will perform almost the same thing as my web application does.
I can use my ASP MVC web application to return json data to my android application, but as I've searched a lot and I was suggested to use Web API for android application.
my question is does it worth to make a dedicated web API with Authentication and Authorization (coz ASP MVC's Authorization is different from Web API's).
Please advice me, would it be any problem if I kept using my ASP MVC web application as json API for android application ?.
you can use an MVC application, you can have some controllers which return JSON data only and call those from anywhere. You still need to authenticate the access to them when you call them from another app though.
Your other option would be to rework your architecture a little. Create a proper WebApi, sort out the authentication to it.
Once you do that, you can call it from both your MVC and any other app that you have, the same way. This way you keep things consistent and your data comes from one place.
If you call your MVC controllers from another app you are basically putting the pressure on the MVC app which now needs to serve an external app as well. Too many calls will then affect the performance of your MVC app.
It's much easier to scale an API properly instead.
I prefer to add JWT security to my APIs. Then your MVC app becomes a client, the mobile app another client, if you need to add some user information, you can, you can also add extra claims to your tokens if and when needed.
Have a look here :
https://jwt.io/introduction/
https://devblogs.microsoft.com/aspnet/jwt-validation-and-authorization-in-asp-net-core/
I used IdentityServer 3 7 4 with good results in the past: https://github.com/IdentityServer/IdentityServer4

User login architecture for Android client and Grails RESTful services

Unfortunately I haven't any tried and tested code for this, simply because I think there may be various ways to do this, but I am simply looking advice on which is best, as security and authentication is not my strong point.
I wish to have initially 2 clients - an android app and a grails based web client, both hitting grails RESTful web services. I have REST resources currently returning some data from the domain when using the web client, next step is to get the same data back into the android app. At the same time I want to integrate some user authentication so that the user must be logged in in order to receive back this JSON data from the REST layer.
In the past I have used Apache Shiro when creating a grails app when only using the grails web based client, is it possible to do the same with an android ap as the client?
In my Grails project with web/android front-ends I'm using for android auth a slightly extended version of SPRING_SECURITY_REMEMBER_ME token (yes, I'm using spring-security-core++ plugin). This fits well in the application, is an easy to implement, tried and tested solution.

Access Heroku database from Android application

I've built a Rails 4 web application with PostgreSQL database and hosted it on Heroku. The future plan for that database is to also be used by one Android application.
I am not completely sure how can I accomplish that. Do I need to build another REST application and host it on Heroku and somehow connect to the same database or there is another way?
How to connect with Android application to that database which is used by the web site? I know I can't connect directly.
Thank you for your guidance.
You don't need another app - just build an API for current one and then you can communicate from Android app to your web application (web app will connect to db and return data).
Have a look at Twitter API as example - you can access different resources and manage them via Twitter API
https://dev.twitter.com/docs/api/1.1
You can build something similar - create rails controllers that access your database and respond with structure you want - preferably JSON format of your models (or something custom if you need)
From Android app you can send request to your API and parse JSON responses - then process data your own way on Android app.
Don't forget about authentication between your Android app and web application - let only your Android app to use it.
I encourage you to browse internet for best practices 'How to create an API' :)

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