Sending a notification to the server when the android app if closed - php

I have created an application which is used to locate other people and a server... Now if anyone closes an app by Advanced Task Killer (This app is used to kill un-necessary application) how do i send a notification or a message to the server saying this person has closed the app.
example:- I have an app which detects other peoples location. And 2 more friends of mine have it. There is a server which examines our location. Now if one of my friend closes the app as said above how do i send a message or notification to the server created.

Before callling finish(); (if ur calling) or in onDestory();
send "closed" as request parameter to your server url like
"http:YOUR_SERVER_URL/?status=closed" using HttpClient post request.
at server catch it as request.getparamer("status");//Its JSP code
if you want inform ur frends about this use C2DM as push notification.

how do i send a notification or a message to the server saying this person has closed the app
You don't. If the user force-stops your app, you do not get control.

Take a look at the activity life cycle. I think what you are looking for, is to call the server in the onDestory() in the current activity...

Related

Send commands from a server to swift app

I am new to swift and was wondering how could I send commands from a server to my iOS application ? For example imagine a website where I can click a button and that button would then trigger a pop up to all users of my app. Is this possible and if so can someone lead me in the right direction?
Much appreciated
Yes, you can
Silent Push Notification: Send a Silent Push Notification and handle in your app. But you need user permissions to receive Notifications. Add "content-available" : 1 to your notification content.
Using Sockets: There are many options to create connection b/w device and server. example: https://socket.io/
It depends what you are trying to do, you might want to look at apple push notifications and see how they work. From there I would suggest looking into sending notifications to the apple server (that would send the push notifications to the app). I hope this sends you in the right path good luck!
I just assume that you have an application that a number of users are using and you have a web application that can show all mobile users.
For the most of cases, whenever a user is using the application, you let the application send a request with your user's information to your server and your server records the user information in the database.
When your website wants to show all the users' information, it just fetches all the information from the database instead of sending sort of commands to all applications to get information in real-time.
Of course, there is a more complex way to send commands to all running applications to get the results. However, it requires both server-side and client-side (ios application) implement functions sending commands in real-time using Socket or MQTT etc. This is more complex and it requires iOS application running in front or background at the same time.
I assume that using HTTP to record every mobile user is more suitable for your case.

How to get messege from server with less data usage in Android?

I am writing a Android program that get message from server. I can refresh my program every second to get message from server, but I don't want to do this work.
Is it possible to send message from server to client IP and then get message with my Android program (that installed in client device)?.
If it is not possible, please say me way to get message from server.
You can use this
1) Use push Notification in your app
2) When user click notification refresh your app (make a http request to your server fetch the update info).
OR
If you don't want to show notification in mobile which is no harm (almost every news app does this). Just don't create notification refresh you app.
for more information refer this
GCM
pushnotification in android

Get data from a server with Objective-C

I'm trying to make a notification system between a PHP server and an iOS device, just like in the Facebook App.
I already know how to make a PHP request via GET or POST and wait for a response. But I would like to receive server's responses without any request, is it possible? Or should I make a request every x seconds?
Look into Apple Push Notification Service (APNS). You send a message to the APNS server, and the server sends a notification to the device(s) you specified. This is standard practice for apps like Facebook.
When the device receives a notification, it sends it to the app (if the app is running) or alerts the user (if it's not). The user can choose to start the app, at which point the notification is delivered. The app can then respond by contacting your server to update its information or whatever.

Openfire and push notifications

I am writing an IOS app that is basically a jabber chat app. I am using Openfire for the xmpp server and so far its been great. The problem I am facing now is with push notifications. The app is written in Xcode which gets user data from a PHP Api. Openfire is the xmpp server. The issue is that when the app sends a message to openfire I would need to also query the Php api to see if the user is online and if they are not, send a push notification. This would have to happen for each message sent and as you might guess that will affect performance with all those requests happening.
I have everything working, I just cant get past this hump. If only openfire would fife off a request of my choice upon receiving a message.
Can anyone suggest a better idea? Basically need to know if the user is online (presence) before so that I know to fire off the push notification and I dont want to fire off two requests from my app per message sent. Thanks.
In openfire the messages to offline users are stored in ofoffline table. So your php code neednot worry about the status of the user if der is any entry in the ofOfline table it means the user was offline. Now create a scheduler that will keep looking in the ofOfline table for offline messages club them together and push notification to the user
i have spen lots of time for in XAMPPHP Library but cant find any proper solution. so for develop a web base chat application with jabber server. rather than using XAMPPHP, you can use "http://strophe.im/strophejs/" it will be much faster than XAMPPHP and you can find more js plugin for Strophe js. and you can also find more ready made xmpp client base on strophe js. so it will better than XAMPHP.

C2DM and PHP Server

I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.

Categories