#NotifyMyAndroidLib (Java)
NotifyMyAndroid is a service which allows you to send push messages to android devices.
NotifyMyAndroidLib
is an object-oriented library (written in Java), which covers the entire API. You only have to fill a request object and hand this object over to the library. For more information, see the chapter 'Usage'.
##Usage
At the moment, the NMA-API has two endpoints, verify
and notify
###Verify
This will verify one API key against the NMA service:
public class VerifyMain {
public static void main(String[] args) throws ConnectorException, ParserException {
VerifyRequest request = new VerifyRequest();
request.setApiKey("API_KEY");
NMAClient nmaClient = new NMAClient();
Result result = nmaClient.request(request);
// isSuccess: true
System.out.println("isSuccess: " + result.isSuccess());
// isError: false
System.out.println("isError: " + result.isError());
// Code: 200
System.out.println("Code: " + result.getCode());
// Type: success
System.out.println("Type: " + result.getType());
// Message: null
System.out.println("Message: " + result.getMessage());
// ResultObject: Result{code='200', message='null', remaining=995, resettimer='50', type='success', isSuccess='true', isError='false'}
System.out.println("ResultObject: " + result.toString());
}
}
###Notify
This will send a push notification to the client(s) identified by the provided API key(s)
public class NotifyMain {
public static void main(String[] args) throws ConnectorException, ParserException {
NotifyRequest request = new NotifyRequest();
request.addApiKey("API_KEY");
request.setContentType(ContentType.TEXT_HTML);
request.setPriority(Priority.NORMAL);
request.setApplication("Test App");
request.setEvent("Event");
request.setDescription("Be<b>schrei</b>bung<br>Beschreibung2");
request.setUrl("http://www.google.de");
NMAClient nmaClient = new NMAClient();
Result result = nmaClient.request(request);
// isSuccess: true
System.out.println("isSuccess: " + result.isSuccess());
// isError: false
System.out.println("isError: " + result.isError());
// Code: 200
System.out.println("Code: " + result.getCode());
// Type: success
System.out.println("Type: " + result.getType());
// Message: null
System.out.println("Message: " + result.getMessage());
// ResultObject: Result{code='200', message='null', remaining=994, resettimer='46', type='success', isSuccess='true', isError='false'}
System.out.println("ResultObject: " + result.toString());
}
}
The NotifyRequest from above looks like this:
Return Codes
All requests will be answered with the HTTP status code 200. This way you will know that you were able to contact the server and the error is an application error or something else.
The response contains a custom code:
Code | Description |
---|---|
200 | Notification submitted. |
400 | The data supplied is in the wrong format, invalid length or null. |
401 | None of the API keys provided were valid. |
402 | Maximum number of API calls per hour exceeded. |
500 | Internal server error. Please contact our support if the problem persists. |
##Installation
###Maven
Using Maven is recommended and its dependencies will be downloaded automatically.
Add the following to the <dependencies>
section in your pom.xml. Click here for Ivy, Gradle, and other configs.
<dependency>
<groupId>de.tobj.nma.client</groupId>
<artifactId>nmaclient</artifactId>
<version>1.0.2</version>
</dependency>
##Configuration
NotifyMyAndroidLib
requires no configuration files but you can define a custom NMA API URL. The default url points to https://www.notifymyandroid.com/publicapi/
new NMAClient("custom-url");
##TODO
- check validity of data (required fields, length, etc...)
##Dependencies
de.tobj.http.httprequestsimple:1.0.2
org.apache.logging.log4j:log4j-api:2.1
##NotifyMyAndroid-API
Documentation is located at http://www.notifymyandroid.com/api.jsp
Authors
TobJ [email protected]