Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ void notifyNotification(Bundle bundle) {
sendEvent("remoteNotificationReceived", params);
}

void notifyDelivered(Bundle bundle) {
WritableMap params = Arguments.createMap();
params.putString("category", bundle.getString("category", ""));
params.putString("type", "ON_NOTIFICATION_DELIVERED");
sendEvent("EventEmitter:sendEvent", params);
}

void notifyNotificationAction(Bundle bundle) {
String bundleString = convertJSON(bundle);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.os.Handler;
import android.os.Looper;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

Expand Down Expand Up @@ -145,7 +150,6 @@ public void handleReceivedMessage(RemoteMessage message) {
bundle.putBoolean("userInteraction", false);
pushNotificationHelper.sendToNotificationCentre(bundle);

/*
// We need to run this on the main thread, as the React code assumes that is true.
// Namely, DevServerHelper constructs a Handler() without a Looper, which triggers:
// "Can't create handler inside thread that has not called Looper.prepare()"
Expand All @@ -157,23 +161,28 @@ public void run() {
ReactContext context = mReactInstanceManager.getCurrentReactContext();
// If it's constructed, send a notificationre
if (context != null) {
handleRemotePushNotification((ReactApplicationContext) context, bundle);
// handleRemotePushNotification((ReactApplicationContext) context, bundle);
RNPushNotificationJsDelivery jsDelivery = new RNPushNotificationJsDelivery(context);
jsDelivery.notifyDelivered(bundle);
} else {
// Otherwise wait for construction, then send the notification
mReactInstanceManager.addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
public void onReactContextInitialized(ReactContext context) {
handleRemotePushNotification((ReactApplicationContext) context, bundle);
// handleRemotePushNotification((ReactApplicationContext) context, bundle);
SharedPreferences sharedPreferences = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("pending_remote_notification", bundle.getString("category", ""));
editor.apply();
mReactInstanceManager.removeReactInstanceEventListener(this);
}
});
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// Construct it in the background
mReactInstanceManager.createReactContextInBackground();
}
// if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
// // Construct it in the background
// mReactInstanceManager.createReactContextInBackground();
// }
}
}
});
*/
}

private void handleRemotePushNotification(ReactApplicationContext context, Bundle bundle) {
Expand All @@ -195,7 +204,7 @@ private void handleRemotePushNotification(ReactApplicationContext context, Bundl
bundle.putBoolean("foreground", isForeground);
bundle.putBoolean("userInteraction", false);
jsDelivery.notifyNotification(bundle);

/*
// If contentAvailable is set to true, then send out a remote fetch event
if (bundle.getString("contentAvailable", "false").equalsIgnoreCase("true")) {
jsDelivery.notifyRemoteFetch(bundle);
Expand All @@ -206,6 +215,7 @@ private void handleRemotePushNotification(ReactApplicationContext context, Bundl

pushNotificationHelper.sendToNotificationCentre(bundle);
}
*/
}

private String getLocalizedString(String text, String locKey, String[] locArgs) {
Expand Down