Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.apache.cordova.firebase;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -22,10 +23,10 @@
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand All @@ -35,6 +36,7 @@
public class FirebasePlugin extends CordovaPlugin {

private FirebaseAnalytics mFirebaseAnalytics;
private static CordovaWebView appView;
private final String TAG = "FirebasePlugin";
protected static final String KEY = "badge";

Expand Down Expand Up @@ -153,11 +155,21 @@ public void onReset() {
FirebasePlugin.tokenRefreshCallbackContext = null;
}

@Override
public void onDestroy() {
super.onDestroy();
System.exit(0);

if (this.appView != null) {
appView.handleDestroy();
}
}

private void onNotificationOpen(final CallbackContext callbackContext) {
FirebasePlugin.notificationCallbackContext = callbackContext;
if (FirebasePlugin.notificationStack != null) {
for (Bundle bundle : FirebasePlugin.notificationStack) {
FirebasePlugin.sendNotification(bundle);
FirebasePlugin.sendNotification(bundle,this.cordova.getActivity().getApplicationContext());
}
FirebasePlugin.notificationStack.clear();
}
Expand All @@ -181,12 +193,22 @@ public void run() {
});
}

public static void sendNotification(Bundle bundle) {
if (!FirebasePlugin.hasNotificationsCallback()) {
public static void sendNotification(Bundle bundle, Context context) {
if(!FirebasePlugin.hasNotificationsCallback()) {
String packageName = context.getPackageName();
if (FirebasePlugin.notificationStack == null) {
FirebasePlugin.notificationStack = new ArrayList<Bundle>();
}
notificationStack.add(bundle);

/* start the main activity, if not running */
Intent intent = new Intent("android.intent.action.MAIN");
intent.setComponent(new ComponentName(packageName, packageName + ".MainActivity"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("cdvStartInBackground", true);

context.startActivity(intent);

return;
}
final CallbackContext callbackContext = FirebasePlugin.notificationCallbackContext;
Expand Down Expand Up @@ -234,7 +256,7 @@ public void onNewIntent(Intent intent) {
final Bundle data = intent.getExtras();
if (data != null && data.containsKey("google.message_id")) {
data.putBoolean("tap", true);
FirebasePlugin.sendNotification(data);
FirebasePlugin.sendNotification(data, this.cordova.getActivity().getApplicationContext());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/android/FirebasePluginMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private void sendNotification(String id, String title, String messageBody, Map<S
bundle.putBoolean("tap", false);
bundle.putString("title", title);
bundle.putString("body", messageBody);
FirebasePlugin.sendNotification(bundle);
FirebasePlugin.sendNotification(bundle, this.getApplicationContext());
}
}
}
2 changes: 1 addition & 1 deletion src/android/OnNotificationOpenReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void onReceive(Context context, Intent intent) {
launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
Bundle data = intent.getExtras();
data.putBoolean("tap", true);
FirebasePlugin.sendNotification(data);
FirebasePlugin.sendNotification(data, context);
launchIntent.putExtras(data);
context.startActivity(launchIntent);
}
Expand Down