package com.selfservit.util;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.FirebaseApp;

import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova. * ;
import org.json.JSONObject;

public class mPushNotification extends CordovaPlugin {
	 @ Override
	public boolean execute(final String action, JSONArray args, final CallbackContext callbackContext)throws JSONException {
		FirebaseApp.initializeApp(cordova.getActivity());
		if (action.equals("GetToken")) {
				try {
				    String token = FirebaseInstanceId.getInstance().getToken();
				    callbackContext.success(token);
				} catch (Exception e) {
				    callbackContext.error(e.getMessage());
				}
		}
		return true;
	}
}

@@ -293,11 +293,71 @@
  %7B%0A%09
- @ 
+private static CallbackContext tokenRefreshCallbackContext;%0A%0A%09@
 Over
@@ -460,16 +460,17 @@
 Context)
+ 
 throws J
@@ -486,16 +486,19 @@
 ion %7B%0A%09%09
+// 
 Firebase
@@ -574,17 +574,16 @@
 en%22)) %7B%0A
-%09
 %09%09%09try %7B
@@ -587,20 +587,16 @@
 y %7B%0A%09%09%09%09
-    
 String t
@@ -647,28 +647,24 @@
 oken();%0A%09%09%09%09
-    
 callbackCont
@@ -682,16 +682,576 @@
 (token);
+%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09callbackContext.error(e.getMessage());%0A%09%09%09%7D%0A%09%09%7Delse if(action.equals(%22TokenRefresh%22))%7B%0A%09%09%09onTokenRefresh(callbackContext);%0A%09%09%7D%0A%09%09return true;%0A%09%7D%0A%09private void onTokenRefresh(final CallbackContext callbackContext) %7B%0A%09%09mPushNotification.tokenRefreshCallbackContext = callbackContext;%0A%0A%09%09cordova.getThreadPool().execute(new Runnable() %7B%0A%09%09%09public void run() %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09String currentToken = FirebaseInstanceId.getInstance().getToken();%0A%0A%09%09%09%09%09if (currentToken != null) %7B%0A%09%09%09%09%09%09mPushNotification.sendToken(currentToken);%0A%09%09%09%09%09%7D
 %0A%09%09%09%09%7D c
@@ -1279,12 +1279,9 @@
 %09%09%09%09
-    
+%09
 call
@@ -1323,30 +1323,462 @@
 %09%09%09%09%7D%0A%09%09
+%09
 %7D%0A%09%09
-return true;
+%7D);%0A%09%7D%0A%09public static void sendToken(String token) %7B%0A%09%09if (mPushNotification.tokenRefreshCallbackContext == null) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09final CallbackContext callbackContext = mPushNotification.tokenRefreshCallbackContext;%0A%09%09if (callbackContext != null && token != null) %7B%0A%09%09%09PluginResult pluginresult = new PluginResult(PluginResult.Status.OK, token);%0A%09%09%09pluginresult.setKeepCallback(true);%0A%09%09%09callbackContext.sendPluginResult(pluginresult);%0A%09%09%7D
 %0A%09%7D%0A%7D%0A

Update mPushNotification.java