How to handle Android to MySQL updates when smartphone is offline - java

I am currently working on a forum-like Android app which interacts with a MySQL database through JSON and PHP scripts. On certain occasions, the app has to send updates to the database, e.g. when a post to the forum is made or updated.
My question considers the situation that the smartphone is offline, i.e. doesn't have a internet connection thus cannot connect to the server, and tries to post something to the forum. However, due to the offline status, it cannot interact with the database immediately. In this situation we want to handle the messages in such a way that the post is sent to the database on the next instnce when the device connects to the internet.
What exactly has to be done on the app side to achieve that?
I guess the post has to be buffered in some directory locally and the app has to check the internet connection constantly. Does anybody know how to do that? Does JAVA provide certain functions for doing this?
Thanks in advance!

Related

How make my API knows the IP of the client, to make a socket communication

I'm developing an android application, and I'm stuck with the notification's thing. The users can be able to like images from other users. When it happens, the user who receive the like have to get a notification. To do that, on the client application, I have a service always running on the foreground and ServerSocket listening. On the other hand, I develop an API which insert the likes on the database. In my opinion, is At that moment when my API have to use a socket to communicate with the client. The problem is that I need the IP of the client to do that. One way to do it would be when the users log in the application save on the database their IP, and when they log out deleted it. I don't know if the IP of a mobile phone is always the same..... in this case it would work, but I don't know if is a good practice...
Somebody knows a better way to do that?

How to make Android app wait for a message from Python on a local server without internet?

Sorry if this is a silly question, I'm still a beginner in Android and couldn't find an answer to my question. I'm making an Android application that sends an input to a server and executes a Python script on that server to process the given input and generates an output. I was successful in sending data from Android client to Python server using SSH.
I can also use SSH to retrieve the output back to the Android client. However, the Python script takes some time to generate the output, and I can't seem to find a way for the Android client to wait for the Python script to finish generating the output. I was able to do this on internet connection with using Firebase database and have the Python script upload the output into Firebase database and have the Android client listen for changes in database. But I'm looking for a way to do this locally without internet (i.e. Firebase).
So is there a way to make my Android application wait for a message from Python to know it has finished with generating the output so it can retrieve it back using SSH or any other way?
Was a protocol what was send a code what was suppost to say if that 2 files are the same. but i do not remember the name. For u will be more easy to send the storage information's in bits (to the device) and after to start that important transfer. when the device will lost the connection will need to compare the real storage memory with the first information's send it and if has not match to ask the user to reconnect to internet or something like that. Maybe is helping until some one will give u the answer.

Is there any way allows my Android wear connect to MYSQL

Just like what I mentioned from the question.
My watch is LG Urban, when I was developing my android app, I can use the mysql connector to connect with my DB server. Can I use the same to make my Android wear connect to mysql?
Thank you!
Starting with Android Wear 2, proxying data requests through the phone has been replaced by direct network access from the watch. So going forward, your existing code to connect to a MySQL server should work essentially unchanged on the watch.
More details here: https://developer.android.com/training/wearables/data-layer/network-access.html
A couple of caveats:
Wear 2 is only now rolling out to the majority of devices (your Urbane probably doesn't have it yet, for example).
You should try to minimize the data being transferred to/from the watch; these devices have enough issues with battery life as it is.
You can talk to the DB via the phone. You can send messages back and forth and also sync data to the wearable.
You could therefore - indirectly - get whatever data you want from the DB and display it on the watch. You could also get sensor data from the watch and save it back to the DB.
https://developer.android.com/training/wearables/data-layer/index.html

Java Server for Android Application

I need to write a server in java that will store integers that are used as stats for my android app. My app has an SQLite database that is already setup that would be useful if I could just pass those contents to the server. I need to do this so that in my multiplayer feature, a player's app will contact the server to know what level their opponent is. (This is not real time). So far I only have a TCP server that opens a client and server socket. Other than that I am not positive what I need to do to make it possible for the server to do what I need. Anyone have suggestions or good tutorials to help me with my problem?
Thanks.
One thing you need to keep track of:
Your SQLite DB has to be used as a player session, until the player logs in as another user. To do this, you have to have one instance of the current logged in player. If you prefer other methods, here's a good list.
I don't think you would need a TCP connection to view the stats, instead implement a REST API in PHP or any other language for back-end that would save, update and look up for a particular player. This is a recommended method. If you are familiar with PHP, this tutorial will give you an idea and full details of what I mean.
Indeed, building a server has many methods. For example, You can use either socket programming or app-server. If you are familiar with web programming, jsp/php/asp.net, you can communicate between your app and server with HTTP requset, which is easy to do.
To be more specific, someone (neme:abc,password:pwd) logging in with your mutiplayer app, when he or she leaves, send the data to server with HTTP request. Then when he or she logging in with other device, you can get the data from status and continues to play. Of course, you can save the data in local with SharedPrefence in Android, too.
By the way, the apache HTTPClient is recommend when using http connection with server.

Create a basic network app

I have a little question about an android app with a function "remote" use via internet.
So I have these ideas:
Create a webservice using php on the server, and refresh the client app all x time like 4-5 sec
Or make a java server (so I don't know how I can do that)
I just want make a remote connected via user/password to the server and the other app connect to the server and refresh his status.
Do you know the best way for do that?
Thanks
The question is not very precise, but as far as I understand it, both your ideas implement the 'pull' concept, that is the client app checking the status of the server every now and then.
If you want the app to be instantly notified of the server status change, I would suggest push notifications with GCM (Google Clound Messaging). You can find some basic descriptions and examples at: http://developer.android.com/google/gcm/index.html
Sending a server-to-client notification is simple regardless of the platform you use server side. E.g. for PHP integration with GCM, check out this thread: GCM with PHP (Google Cloud Messaging)

Categories

Resources