Access Heroku database from Android application - android

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' :)

Related

How can I connect the between web application with an application?

1) I have a web application. This web app is for a user to buy a point.
2) I have an android application for parking payment. Payment is based on point that user buy from the admin. Since I made two things which are web app for admin and android app for user, so I will have two database for each one right?
3) So, how can I transfer the point that user buy from the admin to an android application? Is this thing has to do with JSON fetch or pass data?
4) Basically I want the user to get the point from the web application? Your answer will be really helpful to me, thank you :)
The issue is design issue. Your mobile app and the web app don’t have to be two separate.
You can have one application with one database that both web and mobile point to.
If you’re using Android look into ionic framework that can help you code one codebase targeting both web and mobile.
See
https://ionicframework.com
https://scotch.io/tutorials/create-your-first-mobile-app-with-angularjs-and-ionic
You will have to build a single server for both your admin and your app. Both will have a single database that is controlled by your server. Your app will request the same server to redeem points and your admin will request the server to add points. You can use retrofit library in android for making api calls to your server
The web application and the android application must connect to the same database on the server. In the android application, to you get the data via json, you must use asynctask to download the server information or use libraries like Retrofit or volley that facilitate the handling of json.

Sqlite database login system

I'm trying to create a login system for an android app and I would like to know if creating a Sqlite database solution would work across different devices. For example if I register in a device, could I access the app from another device with that same account without having to register again? If that does not work, what would be the solution? Thanks for the help :)
Ideal solution would be to connect the app to the server for authentication and authorization. The server can be build using any type of database whether it is sqlite or mysql etc. So it does not make any difference.
You can create a web service for the purpose of authentication using php, java or .net (your choice) and the android application can use any web service client framework such as service stack etc. for connecting to the web service.
What kind of authentication and other features you want will depend solely on your application design.
The best option is using a web server. I am doing the same and am using a .net web services for users authentication
For allowing same user to loggin in different devices with same credentials in the app you need to use central database .
Below is the link which will help you a lot.
http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/
Note : Sqlite database is the local database , we can not use it for our central purpose or out of the specific device.

Communication between website and android app

I want to build a website, where the data will be saved in a data base, logical in a sql database. Also, I want to build an android app, which will take the data from the above (sql) data base. How can I achieve it? I mean how can I manage the communication between the website and the android app. In past, I have create website with php and sql and also I have build android apps, but now I want to achieve the communication between them. Can I use parse platform?
FYI, without any server communication you can't use the website database in android application.
If you want to manage the communication between the website and the android app means you need a centralized server which having the data of your web/mobile applications. So, after that by using the web service methods (REST/SOAP) you can achieve the communication between them.
yeah unfortunately chrome won't let webapps use local storage on android. what you can do is create a local server (using org.apache.http package for example), let it run as a background android service, then have the website make requests to that url. Its considered hacky, but it would work. You can post whatever data you wanted the website to know about , and then get it from the website.

json with android mobile application

Hi guys so I am new to android development or any mobile device development.
So I am working on a project that consists of two application.
One with ASP.NET MVC4, one with Android.
what it is doing right now, Android device is accessing database server of ASP.Net application and saves data. This is able because currently, android app has database access information in the codes(db login info).
Since method above is extremely stupid I need help.
So what I am looking into is to use JSON(if possible). ASP.NET MVC4 application is already JSON ready, and i've made sandbox application that brings information from web app to android app. BUT my question here is is it possible to do same thing the other way around. Is it possible to make android application to make JSON and web application to access that application? I dont think this is possible.
So how do other REAL mobile applications save users data on their database server without including db access information within the code?
This is usually done through web api - have a look at twitters api as an example https://dev.twitter.com/docs/api/1.1
You would have to pass data to the server using the api, just as you would use an api to get data from the server.

Android - Rails communication

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.

Categories

Resources