update database of an app from another app in android - java

I need to update and insert rows in Sqlite from another app. I am working on an android app and I have to update database of another app,how can I do that,is it possible to access and edit another app's database from my app.

You should look at Content Providers. From the android official docs
Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process.
Android Docs explain how you can use it.

I understand what you are trying to achieve. correct me if i am wrong. You are developing android application in which you are trying to update your application database by fetching data from some different database. right? if yes, you have to get details of the database server /database connection details from the database owner if possible. in case if the owner of the database is not providing or not ready to give you credentials/database connection details then confirm whether they have any services/webAPI/web services through which they expose database data.
If they have webapi/webservices available then you can easily consume in your andriod application and do what ever operation you want to perform.
Hope this helps..

Related

How to connect android users to my database / web application?

I have wrote a simple web application with few tables. It has it's administration area where you can manage it's table. Basic CRUD operations.
However, I need to develop an Android application which will retrieve information from this web application trough API. So I am going to write a simple API methods for fetching data. Also there will be sometimes when Android user will save some of its data to database.
Android application needs to be able to list items stored in database and bookmark some of those items over HTTP.
To me problem is how to implement SingIn / SignOut operations using Android's Google account. For example, application GMail is always signed in (at least on my device) and I want my application to be always signed in.
Then, how can I manage what items user bookmarked? Should I create a table android_bookmarked_items (android_user_id, item_id)? But then what should be android_user_id? Do I need to use OAuth?
I am doing this kind off sign in for the first time and I am really confused how to connect this web application with android user and manage bookmarked items per user...
You can make use of Android AccountManager. Check out How to get the Android device's primary e-mail address
I think i have found solution by using Google Sign-In for Android. I get idToken for currently login user before each POST request and verify it on server side. Also from the token I get property sub which is user id and store this in my database...
Auth with a backend server
However, I am pretty new to this stuff, tokens and authentication using google, I would like for someone more experinced to confirm that my solution is fine and secure...

Android Google CloudSQL

Currently I stored data from my Android / Java app in SQLite on the device. I want to dump this delimited/structured data to a mysql insance on Google CloudSQL. I have a google cloud account, setup a DB and have the cloud back end all ready. I have plenty of DB experience but am weak on java, cloud, etc After months of seeking working examples (GAE?) I know about this link:
https://cloud.google.com/appengine/docs/java/cloud-sql/
But it's not complete.
Can someone just post a very simple app that successfully executes a simple insert from Android/Java into Google CloudSQL and include all the code needed to get the data to the CloudSQL instance?
If this is a duplicate question and the complete code sample is already on StackOverflow I will gladly read it. I have not found a complete example yet.
Thanks in advance.
Try using Firebase or Realm instead to facilitate data flow to your mobile App. Firebase is built on reactive programming model where data is saved in Friebase and automatically synced with client device. Realm goes a step ahead in having you abstract a true API call via its interface. And otherwise yes as others responded your mobile app HAS to actually call an API service and not CloudSQL directly

How can we add a server-side Java code in Firebase?

Scenario:
I am planning to build a system that has 2 components. A Web App (Angular) that would push some data to Firebase. Before the data gets pushed , I want it to get validated by a server-side Java code. The data getting pushed to Firebase is fed to an Android application that consumes the data from Firebase. The Android user can perform some actions like changing the state of data. Before the data gets changed again there should be a server side code to validate it.
Question:
Where does the server-side code reside? Do we need a third party Web App hosting service other than Firebase?
If my code is in Java 7, what can be the possible options available?
If at all we use a third party server, how does the server communicate with a Firebase server?
Also can you please help me understand (if possible) how can we make sure that the data getting pushed to Firebase server gets validated by the server-side code before getting pushed?
firebaser here
You can interact with the Firebase Database through its Java SDK.
Firebase does not currently provide a way for you to run your (Java) code on our servers. We've covered this many times already, so I recommend reading up here: Server Side Calculation using Firebase
So you'll indeed have to host that code at a third party. Recommending a specific host is off-topic on Stack Overflow, but there are undoubtedly a lot of results of you search for Java hosting.
A common way to have server-side validation before sharing the data publicly is to have two separate lists.
moderationList
-K.....1
title: "how can we add a server side java code in firebase"
body: "Scenario: I am planning to build a system..."
messageList
-K.....2
title: "Firebase and backend logic"
body: "I am parse.com user, and now I look..."
Your users view messageList, but they write their items to moderationList. Your Java server code monitors this list, validates the item and then adds the item to messageList. This is a common queue pattern that we use a lot internally at Firebase.

SQLite, MySQL or Both for Android Application

I'm in the process of designing an Android application right now.
I understand SQLite works on the phone device within the file structure. However I'm not sure if it's practical for our use.
If I'm wanting to store data that's available to all users (i.e. if someone updates their profile, it can be seen by all other users), can that be done using SQLite somehow? Or must we use a client-server model such as MySQL?
Is it practical to store user-specific information using SQLite and public information using MySQL?
Thank you
What you want to do is a Client-Server Architecture, store the data in your central server and get a copy of the working data on the phone. MySQL and SQLite don't share everything but it's close. Read the documentation on SQLite and you will see.
SQLite can't serve files like MySQL if that's your question via the network. You'll have to write that on your own. I suggest making a webservice.
If you want info to be available to all users you need a client-server model such as MySQL.
If you use SQL Lite, the only possible way to update that info without requesting it from a server is to make an Update on the application (not doable).
Don't forget that you'll require internet ON for these types of applications.
you mean all users going to use a single phone, probably not, the reason for recommending sqlite database for android is that its the lightweight, non memory eater and thus best suitable to mobile phones. Sqlite database can be used in phone while at server side we can use any. The only thing is use a method like sending xml request to server from phone, where server will send respond as xml or json, while the phone parse the xml and use the data in it. this is how online apps works in mobile phones..... ya ofcourse use mysql at server side and do the communication using as request - response yes the client-server.
Is it practical to store user-specific information using SQL Lite and public information using MySQL?
Yes, This is exactly what I'm doing with my app. It's a very common practice. I am storing information in a MySql db stored on a server that all users can read from. They can pull specific information to the device. From there I have a class in the app that stores information that they've selected within a SQLite db. You'll easily be able to add information to the MySql db on the server that all users can view.
yeah i think the model you are proposing should have no problem. Even i'm using a model something similar to what you are saying. I store some information on local sqlite db and majority of information in mysql db. For sending data from android device to mysql db you will have to write a mysql scipt on a page and android device will hit that page with the help of http request. You can send your data in that http request

Post information to server and receive XML

On my web server I will be creating a custom XML file for a client app to access. This means I must authenticate the client and then give the client the XML file.
I believe the client application will need to post data (login, password) to the server and once a connection is established, it will receive the XML file from the server (most likely PHP).
If you have any advice, it would be most welcomed: particular classes to look at and any potential dangers.
I found something relevant in C#, however I am limited to Java as the app will be for Android.
Android lets you pull in external jar's, so I would use HttpClient for performing your POST operation with login info.((EDIT: Per Samuh in the comments, this is already a part of the android SDK, no need to include the external version))
Once you have the XML data in your application, you can parse it however you see fit. I would create a SQLite database for your application to store the data parsed in from the XML file. Then, when you run your app, (or the user clicks refresh), pull the XML file down, populate the SQLite DB with the data from it, and hook the UI controls to the database as done in the Notepad tutorial
The advantages of this setup are that you can always have a local copy to show the user if they are offline, and the user can quit, pause, or leave the app open or closed and not lose the information. You should implement both a refresh on demand and a regular refresh with Alarm's setInexactRepeating() so the application will update automatically in the background in a battery life maintaining way.
That should be enough to get you started.

Categories

Resources