I wrote an item selling system using PHP and android.php app for sellers and android app for buyers.with android app buyers can order items from php server app.I used a slim rest API to do that.that part is ok.server app users can accept or deny buyer requests.
Now I need to get that response to android app.i used volley to send requests to server.how can I do that.
Need a code sample
You should use something like Firebase Cloud Messaging instead of regular polling to a REST API.
So when you receive message from Firebase, you can update the data accordingly.
You also may want to check Firebase Real-time database. Search for it in Google.
If you don't want to use Firebase, when response of API call comes to the app, wait for some time and make API call again.
Make a method to initiate an API call, and when you receive the response, update the UI and call that method again after some time using Handler#postDelayed
Related
I want to build an app that continues an only one group maybe with API.
Someone can guide me with this, please?
It's for an Educational app.
One option you have is to work with a server.
On your server, you host a database and an API. You can use the database to save the users and the messages. You should also send your push notifications with this server. You can send push using FCM, but I personally had some problems with it and switched to OneSignal.
In your APP you can show the different messages using a ListView with custom list items. To communicate between server and app you can use a Volley request.
Some time ago I wrote nearly the same app. I would recommend you to use a server with an API (a simple PHP API is enough).
I am developing a backend service that sends push notifications to mobile apps via either FCM or APNS. I would like to create an automated test that can run in under a minute and validates that the server can successfully send a notification. Note that I do not necessarily need to check that the notification has been delivered, just that FCM or APNS has successfully processed the request to send the message.
I know that theoretically I could automate this test using a tool like appium and use test hooks to retrieve a registration/device token from the app, but it seems cumbersome to use appium to test if the backend can send a message. I have also tried to use a hard coded registration token, but registration and device tokens are prone to rotate, so the test could suddenly stop passing. Are there any other options?
First of all, I would think about what scenario do we want to cover.
Maybe, we want to check that we sent a request to FCM when it is needed. This case might be done on a unit level with mocked classes responsible for sending a push.
If you want to test specifically success of the FCM call, then you don't actually need a correct Firebase token of the user device. According to docs, if everything is configured correctly and you send a message to a user using incorrect token (or even without it), you will still get http code 200. As a result, you may use usual integration test that will call Firebase API and check the success code (200) and error field (MissingRegistration / InvalidRegistration / NotRegistered), and if you get such a pair - your request was succesfull. There is no much need to test it with a correct user device token, because if everything else is correct, the result will be the same (but actually delivered to a phone).
Firebase docs
In case if you still want to use an actual token, you can create a special build type for you QAs, that will send their Firebase token to a special endpoint on your server on each app start. As a result, you will always have a recent Firebase token stored on your server to use for test purposes. Of course, that test may still be flacky but it is a good starting point.
Appium is automation framework for black-box testing, so in your case, it allows to check if the notification pops up on a device. And that's it.
Appium has no access to your application code, you can send adb commands via it, but basically, no way to play with tokens until you expose it to the UI layer of your app.
Moreover, Appium is not supported by Firebase.
I suggest looking into Espresso, where you write tests with direct access to your application code.
You can write cloud functions to achieve this in firebase which can be pushed using firebase CLI from local system.This cloud functions can be written in Nodejs. You can go this documentation for writing cloud functions. https://firebase.google.com/docs/functions/ These cloud functions can be triggered on some events like change in real time database,when user signup etc. and you can get tokens from mobile app using callbacks on registered listeners and we can use them to push notifications to app. You can go through following simple project. https://aaronczichon.de/2017/03/13/firebase-cloud-functions/
I am trying to build an app which will send notifications to the users according to the data changes from Rest API.
i.e A user subscribes that he wants to be notified when Spain scores the goal against Portugal. So my question is, is it possible to connect that link which sends requests to Rest API which I'm using to retrieve data to FCM or should I look for other product which will solve my problem?
You could do it with Cloud Functions, which "run backend code in response to events triggered by Firebase features and HTTPS requests", see the general doc here.
You could regularly trigger an HTTPS Cloud Functions that would:
Call the REST API, e.g. with Request (https://github.com/request/request)
Based on the response of the REST API, send a notification with FCM.
To send a FCM notification via Cloud Function, have a look a this official Firebase sample https://github.com/firebase/functions-samples/tree/master/fcm-notifications
To call your HTTPS Cloud Function regurlarly, you have to trigger it via http through a cron-job.
Have a look at: https://firebase.google.com/docs/functions/http-events and
https://www.youtube.com/watch?v=CbE2PzvAMxA. You could also use another online CRON service to call the HTTPS Function, like https://www.easycron.com/
Note that you would need to be on Blaze Plan to be able to query an outside service.
I created android app that connects with MySql in phpAdmin by Json code and the app works well with me. I want when the admin add a new row in the table that in server, the app knows that the new data added, meaning that I want the app updated with sever forever.
How to do this?
Thanks in advance.
Schedule a request to the server every once in a while or let have a REFRESH button in your app. For the request to the server use an AsyncTask and s
Inside onPostExecute update your UI.
Check the AyncTask docs here
Its better to use GCM (Google Cloud Messaging) for Android and Push Notifications when ever you update your Mysql data, so that your app can connect to your server and download refreshed data accordingly, Saves Battery and improves your app performance.
Tutorial Here: http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/
I have an android app which i connect to my server using REST API (django rest framework)
here is a scenario(and maybe my plan):
data is sent back and forth as json
I have a user model and a task model where users are owners of some task.
Users typicaly sends a task to another user (with json similar to this: {"owner": "exampleuser", "from":"otheruser", "content":"example" ...} using POST method)
-The tasks has a boolean field "completed" and is deleted once the task is completed (using PUT or PATCH method: completed = true,)
once a new task gets created using POST method, the only way users can see any activities concerning their tasks is through an android activity that uses GET method to get a list of all the tasks owned by the user, by looking up all objects owned by the user
So my questions are:
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
How will it tell which user or device to send the push notification to?
How does GCM knows when there has been a change to tasks or when a user POST a task?
Android keeps one active connection to Google's servers, but it doesn't use much power or data, because no traffic is sent along it until something sends a GCM message to an app on your phone. There's only one connection on the phone, used by all apps: installing a new app that uses GCM doesn't add any extra load.
The first step in GCM is that a third-party server (such as an email server) sends a request to Google's GCM server. This server then sends the message to your device, through that open connection. The Android system looks at the message to determine which app it's for, and starts that app. The app must have registered with Android to use GCM, and it must have the relevant permission. When the app starts, it might create a notification straight away with the data from the message. GCM messages are very limited in size, so the app might instead open a normal connection to the third-party server to get more information (for example, downloading the headers of new emails).
The advantage of using push notifications is that apps don't have to run at regular intervals to check for new data, saving both power and data. The advantage of having a centralized mechanism like GCM is that the device only needs one open network connection and the Android GCM system is the only thing that needs to keep running, rather than each app having to stay running in the background to keep its own network connection to its own server.
As per the GCM implementation, it requires that you implement a remote server which will manage all the requests, both incoming and outgoing. You can do this simply with a web server acting as a webservice, which will get (for instance) the requests from the clients with a HTTP POST request, and process act consequently.
Instead of having the user to check the app everytime. How can I use GCM to push notify the user?
This will be managed by the server that I just described. It will know who is subscribed and who should receive the notifications.
How will it tell which user or device to send the push notification to?
Same goes here. The server, upon a subscription, should store the users in some kind of storage (a SQL database, for instance), and this way it will know who to send notifications. This implies you'll have to implement some timeout mechanism. In my case, I make clients send a dummy HTTP POST every 30 seconds. If I don't get this request from a reasonable amount of time, I consider the client timed-out and therefore I remove them from the database.
How does GCM knows when there has been a change to tasks or when a user POST a task?
Same story, it's all handled by the server. You implement the logic of what should happen upon any request.
You might want to read this: How to send location of the device on server when needed
And also this references:
Reference on Google Cloud Messaging
Android Push Notifications using Google Cloud Messaging GCM - Android Example
Google Cloud Messaging using PHP
Connection between PHP (server) and Android (client) Using HTTP and JSON
Notificaciones Push Android: Google Cloud Messaging (GCM). ImplementaciĆ³n Cliente (Nueva VersiĆ³n) (spanish)