|
20 | 20 | import com.getcapacitor.Plugin; |
21 | 21 | import com.getcapacitor.PluginHandle; |
22 | 22 |
|
| 23 | +import org.json.JSONException; |
| 24 | +import org.json.JSONObject; |
| 25 | + |
23 | 26 | import ee.forgr.capacitor.social.login.GoogleProvider; |
24 | 27 | import ee.forgr.capacitor.social.login.ModifiedMainActivityForSocialLoginPlugin; |
25 | 28 | import ee.forgr.capacitor.social.login.SocialLoginPlugin; |
26 | 29 |
|
27 | 30 |
|
| 31 | +//import android.app.NotificationChannel; |
| 32 | +//import android.app.NotificationManager; |
| 33 | +//import android.os.Build; |
| 34 | +//import com.google.firebase.messaging.RemoteMessage; |
| 35 | +//import com.capacitorjs.plugins.pushnotifications.MessagingService; |
| 36 | + |
| 37 | +//public class MyMessagingService extends MessagingService { |
| 38 | +// |
| 39 | +// @Override |
| 40 | +// public void onMessageReceived(RemoteMessage remoteMessage) { |
| 41 | +// // TODO(developer): Handle FCM messages here. |
| 42 | +// // Not getting messages here? See why this may be: https://goo.gl/39bRNJ |
| 43 | +// Log.d(TAG, "From: " + remoteMessage.getFrom()); |
| 44 | +// |
| 45 | +// // Check if message contains a data payload. |
| 46 | +// if (remoteMessage.getData().size() > 0) { |
| 47 | +// Log.d(TAG, "Message data payload: " + remoteMessage.getData()); |
| 48 | +// |
| 49 | +// if (/* Check if data needs to be processed by long running job */ true) { |
| 50 | +// // For long-running tasks (10 seconds or more) use WorkManager. |
| 51 | +// scheduleJob(); |
| 52 | +// } else { |
| 53 | +// // Handle message within 10 seconds |
| 54 | +// handleNow(); |
| 55 | +// } |
| 56 | +// |
| 57 | +// } |
| 58 | +// |
| 59 | +// // Check if message contains a notification payload. |
| 60 | +// if (remoteMessage.getNotification() != null) { |
| 61 | +// Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); |
| 62 | +// } |
| 63 | +// |
| 64 | +// // Also if you intend on generating your own notifications as a result of a received FCM |
| 65 | +// // message, here is where that should be initiated. See sendNotification method below. |
| 66 | +// } |
| 67 | +//} |
| 68 | + |
| 69 | + |
28 | 70 | public class MainActivity extends BridgeActivity implements ModifiedMainActivityForSocialLoginPlugin { |
29 | 71 |
|
30 | 72 | // Declare this at class level |
@@ -60,20 +102,21 @@ public boolean isNativeApp() { |
60 | 102 | protected void onNewIntent(Intent intent) { |
61 | 103 | super.onNewIntent(intent); |
62 | 104 |
|
63 | | - String data = intent.getDataString(); |
64 | | - Log.i("CompassApp", "onNewIntent called with data: " + data); |
65 | | -// if (data != null && data.startsWith("com.compassmeet://auth")) { |
66 | | -// Log.i("CompassApp", "triggerWindowJSEvent oauthRedirect"); |
67 | | -// try { |
68 | | -// String payload = new JSONObject().put("data", data).toString(); |
69 | | -// Log.i("CompassApp", "Payload: " + payload); |
70 | | -// bridge.getWebView().post(() -> bridge.getWebView().evaluateJavascript("oauthRedirect(" + payload + ");", null)); |
71 | | -// } catch (JSONException e) { |
72 | | -// Log.i("CompassApp", "Failed to encode JSON payload", e); |
73 | | -// } |
74 | | -// } else { |
75 | | -// Log.i("CompassApp", "No relevant data"); |
76 | | -// } |
| 105 | +// String data = intent.getDataString(); |
| 106 | + String endpoint = intent.getStringExtra("endpoint"); |
| 107 | + Log.i("CompassApp", "onNewIntent called with endpoint: " + endpoint); |
| 108 | + if (endpoint != null) { |
| 109 | + Log.i("CompassApp", "redirecting to endpoint: " + endpoint); |
| 110 | + try { |
| 111 | + String payload = new JSONObject().put("endpoint", endpoint).toString(); |
| 112 | + Log.i("CompassApp", "Payload: " + payload); |
| 113 | + bridge.getWebView().post(() -> bridge.getWebView().evaluateJavascript("bridgeRedirect(" + payload + ");", null)); |
| 114 | + } catch (JSONException e) { |
| 115 | + Log.i("CompassApp", "Failed to encode JSON payload", e); |
| 116 | + } |
| 117 | + } else { |
| 118 | + Log.i("CompassApp", "No relevant data"); |
| 119 | + } |
77 | 120 | } |
78 | 121 |
|
79 | 122 | @Override |
@@ -124,6 +167,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { |
124 | 167 |
|
125 | 168 | // This function will never be called, leave it empty |
126 | 169 | @Override |
127 | | - public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() {} |
| 170 | + public void IHaveModifiedTheMainActivityForTheUseWithSocialLoginPlugin() { |
| 171 | + } |
128 | 172 | } |
129 | 173 |
|
0 commit comments