In this tutorial, you will learn, how to automate the Push Notification for Ionic 2 project using the Java. This tutorial focuses the Server side only.

Before that, you need to create a basic working Ionic 2 Push Notification project.

https://ampersandacademy.com/tutorials/ionic-framework-version-2/push-notification-in-ionic-2-native-plugin-version-2-3-with-firebase-hosting-service-provider

Use the above link to create a simple working Push Notification project using the Ionic 2.

Use the Java Code to send Push Notification.

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;

import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class Push {

public static void main(String[] args) throws Exception {

String url = "https://android.googleapis.com/gcm/send";
String API_ACCESS_KEY="YOUR_API_KEY";

String registrationIds="DEVICE_REGISTRATION_ID";

URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();

//add reuqest header
con.setRequestMethod("POST");

con.setRequestProperty("Authorization", "key="+API_ACCESS_KEY);

con.setRequestProperty("Content-Type", "application/json");

String urlParameters = "{\"data\":{\"message\":\"Sample Message\"},\"registration_ids\":[\""+registrationIds+"\"]}";

// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

//print result
System.out.println(response.toString());

}
}

Replace the YOUR_API_KEY with Firebase Cloud Messaging API key. And also replace the DEVICE_REGISTRATION_ID with your device registration id.