Push Sender is a Java library that allows sending push messages easily, based on the awesome libraries gcm-server by theganyo and java-apns by notnoop. Be sure to check them out! Send push messages with one line of code, forget about the rest, and focus on making your application's business logic!
Using Push Sender is very simple. You can import Push Sender on your POM file using:
<dependency> <groupId>com.devsu</groupId> <artifactId>push-sender</artifactId> <version>1.0.3</version> </dependency> You can send your push messages synchronously and asynchronously by choosing any of the implementations of PushService.
publicclassMySender{SyncAndroidPushServicesyncAndroidService = newSyncAndroidPushService(GCM_API_KEY); AsyncAndroidPushServiceasyncAndroidService = newSyncAndroidPushService(GCM_API_KEY, null); SyncApplePushServicesyncAppleService = newSyncApplePushService(P12_FILEPATH, P12_PASSWORD, IS_PRODUCTION_ENVIRONMENT); AsyncApplePushServiceasyncAppleService = newAsyncApplePushService(P12_FILEPATH, P12_PASSWORD, IS_PRODUCTION_ENVIRONMENT, null); ... publicvoidsendSomePushMessages(){Stringtitle = "My Push Message Title"; Stringcontent = "Hello! This is a push message!"; syncAndroidService.sendPush(title, content, ANDROID_PUSH_TOKEN); asyncAndroidService.sendPush(title, content, ANDROID_PUSH_TOKEN); syncAppleService.sendPush(title, content, IOS_PUSH_TOKEN); asyncAppleService.sendPush(title, content, IOS_PUSH_TOKEN)} ... }You can implement a PushCallback for any of the asynchronous services.
publicclassMySender{... publicvoidsendSomePushMessages(){AsyncAndroidPushServiceasyncAndroidService = newSyncAndroidPushService(GCM_API_KEY, newPushCallback(){@OverridepublicvoidonSingleSuccess(booleanresult, Stringtitle, Stringmessage, Map<String, String> additionalFields, Stringtoken){System.out.println("The single message was successfully sent!")} @OverridepublicvoidonError(Throwablet){System.err.println("Oops... Something happened!")} @OverridepublicvoidonBulkSuccess(booleanresult, Stringtitle, Stringmessage, Map<String, String> additionalFields, String[] tokens){System.out.println("The bulk message was successfully sent!")} })} ... }- You can customize any data sent on your push message with a
Map<String, String>that contains any key-value pair you want to send. - You can build your
Message.BuilderorPayloadBuilderobjects externally and send them as push messages! - You can customize settings like max retries, collapse keys, production/sandbox environments, bulk size when sending simultaneous push messages on Android and more...
Feel free to contact Alvaro López at rion18@hotmail.com!
Copyright 2015 Devsu Software
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.