Cloud service for pushing android notifications
Android Push Notification Service (APNS) is a free to use library for pushing the data to android devices, all you need is to download the library and start the service in your app. the library use our cloud servers, so you needn't pay for the expensive servers hosting
How it works
Once the APNS service is start on device, APNS-Cloud will keep a permanent TCP connection with them, when you need push something to them, send a http rest request to APNS-Cloud, and APNS-Cloud will send the data to the device.
Getting start
Now, let's take a few minutes to push a message to your android device. first, you need install the demo on your device (click the left download demo or scan the QR code to download).
start the service on your device, input a unique id (any string, you will use it to identify your device bellow). after the service start seccessfully, type the command in bellow emulate shell:
pushto <unique id> <some string>, for example, if i want to push a "hello" to my device which id is set to "abc",
the command will to be: pushto abc hello. if there is no thing goes wrong, your device will receive the message you send to.
Integrate with your app
It's very easy to integrate the service to your own app, the details is in Document section.
Using APNS in your app
1. Download the lastest apns java library (apns_x.x.x.jar), add it to the "Java Build Path" of your project.
2. Create your own broadcaster class which extends from BroadcastReceiver, handlethe "APNService.ON_NOTIFICATION" intent:
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(APNService.ON_NOTIFICATION)) {
String str = intent.getStringExtra("data");
//todo, handle the data received
}
}
}
3. Start the service in your app:
Intent intent = new Intent(APNService.START);
intent.putExtra("ch", channel);
intent.putExtra("devId", devId);
startService(intent);
channel: the chanel id, each app key is asigned to one chanel, login to developer to see what it is. devId:the id used to identify your device in the chanel. when push, will use it find out which device should receive the message.
4. Config the manifest xml:
...
<application android:icon="@drawable/icon"
...
<service android:name="com.apns.APNSService" android:label="APNS">
<intent-filter>
<action android:name="com.apns.APNService.START" />
<action android:name="com.apns.APNService.STOP" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</service>
<receiver android:name="MyBroadcastReceiver">
<intent-filter>
<action android:name="com.apns.APNService.NOTIFICATION" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
...
Push the message to your device
APNS use REST API to delivery the message to target device, so you just send a url request to the server
http://www.push-notification.org/handlers/apns_v1.php?ch=YourChannelId&
devId=YourDevId&msg=helloooo&random=0123&hash=hash
ch: the channel id,
devId: target device id,
msg: message,
random: message,
hash: md5(ch + devId + msg + random + apiKey).
you will get a response with the string in xml format:
<response result=”0” msg=”sent” />
error code:
-1: can't connect to the cloud;
0: send seccessfully;
1: access failed;
2: permission failed;
3: device not online;
12: the chanel expired;
13: hash code not match;
14: illege parameter;
15: unknown exception;
you can download the full demo code in Download.
SDKs
There are all files you need,
include apns.jar,
examples (php, java) and docs.
DOWNLOAD
username: |
|
password: |
|
| login |
Version
v1.0.6release on 2012-11-29- bug fixed: can not receive notifications after device wake up
- fixed the bug: can not receive notification after switching network.
- decrease the reconnect time to 60 sec.
- increase the max message length to 1024 bytes.
- support using one chanel with different apps in one device.
- setup the server cluster
- modified client library: use the fastest server for tcp connection
- v1.0.0 library released for android developers.
- improved the performance of server.
- fixed servial bugs of client library.
- the beta version for java library is released with the basic functions.
- apns server in online.
