Advertisement
hasancse1991

Untitled

Oct 6th, 2020
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.11 KB | None | 0 0
  1. package com.grameenphone.chitchat.utility;
  2.  
  3. import android.content.ComponentName;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.content.ServiceConnection;
  7. import android.os.Bundle;
  8. import android.os.IBinder;
  9. import android.util.Log;
  10.  
  11. import com.applozic.mobicomkit.Applozic;
  12. import com.applozic.mobicomkit.api.account.register.RegisterUserClientService;
  13. import com.applozic.mobicomkit.api.account.register.RegistrationResponse;
  14. import com.applozic.mobicomkit.api.account.user.MobiComUserPreference;
  15. import com.applozic.mobicomkit.api.notification.MobiComPushReceiver;
  16. import com.applozic.mobicomkit.uiwidgets.call.CallActivity;
  17. import com.applozic.mobicomkit.uiwidgets.call.CallService;
  18. import com.applozic.mobicomkit.uiwidgets.call.CallingClient;
  19. import com.google.firebase.messaging.RemoteMessage;
  20. import com.sinch.android.rtc.SinchHelpers;
  21. import com.sinch.android.rtc.calling.Call;
  22. import com.sinch.android.rtc.calling.CallClient;
  23.  
  24. import java.util.HashMap;
  25. import java.util.Map;
  26.  
  27. import static android.content.Context.BIND_AUTO_CREATE;
  28. import static com.android.volley.VolleyLog.TAG;
  29.  
  30. public class FCMHelper {
  31.  
  32.     private static String TAG = "FCMHelper";
  33.  
  34.     public static void onNewToken(Context ctx, String registrationId) {
  35.  
  36.         Log.e("SDK-Helper-FCM-Token", registrationId);
  37.  
  38.         Applozic.getInstance(ctx).setDeviceRegistrationId(registrationId);
  39.         if (MobiComUserPreference.getInstance(ctx).isRegistered()) {
  40.             try {
  41.                 RegistrationResponse registrationResponse = new RegisterUserClientService(ctx).updatePushNotificationId(registrationId);
  42.             } catch (Exception e) {
  43.                 e.printStackTrace();
  44.             }
  45.         }
  46.  
  47.     }
  48.  
  49.     public static void onMessageReceived(final Context context, RemoteMessage remoteMessage) {
  50.         Map data = remoteMessage.getData();
  51.         Log.e("SDK-Helper", "onMessageReceived");
  52.  
  53.         if (remoteMessage.getData().size() > 0) {
  54.             if (MobiComPushReceiver.isMobiComPushNotification(remoteMessage.getData())) {
  55.                 Log.e(TAG, "Applozic notification processing...");
  56.                 MobiComPushReceiver.processMessageAsync(context, remoteMessage.getData());
  57.                 return;
  58.             }
  59.         }
  60.  
  61.         if (SinchHelpers.isSinchPushPayload(remoteMessage.getData())) {
  62.  
  63.             Log.e("Push", " received data: " + remoteMessage.getData());
  64.  
  65.             StoreData storeData = StoreData.getInstance();
  66.  
  67.             Bundle bundle = new Bundle();
  68.             bundle.putString("sinch", remoteMessage.getData().get("sinch"));
  69.  
  70.             Intent localIntent = new Intent("incomingCall");
  71.             localIntent.putExtras(bundle);
  72.             context.sendBroadcast(localIntent);
  73.  
  74. //            CallingClient.getInstance().initialize(context, storeData.getData(context, StoreData.USER_ID));
  75. //            CallingClient.getInstance().getSinchClient(context).relayRemotePushNotificationPayload(remoteMessage.getData());
  76.  
  77.         }
  78.     }
  79. }
  80.  
  81.  
  82.  
  83. //            new ServiceConnection() {
  84. //
  85. //                private Map payload;
  86. //
  87. //                @Override
  88. //                public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
  89. //                    Log.e(TAG, "onServiceConnected");
  90. //                }
  91. //
  92. //                @Override
  93. //                public void onServiceDisconnected(ComponentName componentName) {
  94. //                    Log.e(TAG, "onServiceDisconnected");
  95. //                }
  96. //
  97. //                @Override
  98. //                public void onBindingDied(ComponentName name) {
  99. //                    Log.e(TAG, "onBindingDied");
  100. //                }
  101. //
  102. //                @Override
  103. //                public void onNullBinding(ComponentName name) {
  104. //                    Log.e(TAG, "onNullBinding");
  105. //                }
  106. //
  107. //                public void relayMessageData(Map<String, String> data) {
  108. //                    payload = data;
  109. //                    context.bindService(new Intent(context, CallService.class), this, BIND_AUTO_CREATE);
  110. //                }
  111. //            }.relayMessageData(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement