xl121 1 year ago
parent
commit
a25cdec638

+ 7 - 4
TMessagesProj/src/main/java/org/telegram/cricdit/ui/SplashActivity.java

@@ -20,12 +20,15 @@ public class SplashActivity extends Activity {
 
     protected void initView() {
 //        boolean isFirstLaunch = SPUtils.getInstance().get("isFirstLaunch", true);
-//        if (isFirstLaunch) {
+
+        if (getIntent().getExtras() == null) {
             startActivity(new Intent(this, LaunchActivity.class));
             finish();
-//        } else {
-//
-//        }
+        } else {
+            Intent intent = getIntent();
+            intent.setClass(SplashActivity.this, LaunchActivity.class);
+            startActivity(intent);
+        }
 
     }
 }

+ 59 - 2
TMessagesProj/src/main/java/org/telegram/messenger/GcmPushListenerService.java

@@ -8,11 +8,24 @@
 
 package org.telegram.messenger;
 
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.os.Build;
+import android.text.TextUtils;
+
 import androidx.annotation.NonNull;
+import androidx.core.app.NotificationCompat;
 
 import com.google.firebase.messaging.FirebaseMessagingService;
 import com.google.firebase.messaging.RemoteMessage;
 
+import org.telegram.onecric.ui.activity.CricketDetailActivity;
+
 import java.util.Map;
 
 public class GcmPushListenerService extends FirebaseMessagingService {
@@ -26,8 +39,11 @@ public class GcmPushListenerService extends FirebaseMessagingService {
         if (BuildVars.LOGS_ENABLED) {
             FileLog.d("FCM received data: " + data + " from: " + from);
         }
-        System.out.println("werwqeer 2   " + data.get("p"));
-        PushListenerController.processRemoteMessage(PushListenerController.PUSH_TYPE_FIREBASE, data.get("p"), time);
+//        System.out.println("werwqeer 2   " + data);
+
+        sendNotification(message);
+
+//        PushListenerController.processRemoteMessage(PushListenerController.PUSH_TYPE_FIREBASE, data.get("p"), time);
     }
 
     @Override
@@ -42,4 +58,45 @@ public class GcmPushListenerService extends FirebaseMessagingService {
             System.out.println("werwqeer 1   " + token);
         });
     }
+
+    /**
+     * Create and show a simple notification containing the received FCM message.
+     *
+     * @param messageBody FCM message body received.
+     */
+    private void sendNotification(RemoteMessage remoteMessage) {
+        Intent intent = new Intent();
+        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+        Map<String, String> bundle = remoteMessage.getData();
+        if (bundle.size() > 0) {
+            intent.setClass(this, CricketDetailActivity.class);
+            intent.putExtra("matchId", Integer.parseInt(bundle.get("matchId")));
+            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
+                    PendingIntent.FLAG_IMMUTABLE);
+
+            String channelId = "fcm_default_channel";
+            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+            NotificationCompat.Builder notificationBuilder =
+                    new NotificationCompat.Builder(this, channelId)
+                            .setSmallIcon(R.mipmap.ic_launcher)
+                            .setContentTitle("FCM Message")
+                            .setContentText(remoteMessage.getNotification().getBody())
+                            .setAutoCancel(true)
+                            .setSound(defaultSoundUri)
+                            .setContentIntent(pendingIntent);
+
+            NotificationManager notificationManager =
+                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+
+            // Since android Oreo notification channel is needed.
+            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                NotificationChannel channel = new NotificationChannel(channelId,
+                        "Channel human readable title",
+                        NotificationManager.IMPORTANCE_DEFAULT);
+                notificationManager.createNotificationChannel(channel);
+            }
+
+            notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
+        }
+    }
 }

+ 41 - 0
TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java

@@ -19,6 +19,8 @@ import android.annotation.SuppressLint;
 import android.app.Activity;
 import android.app.ActivityManager;
 import android.app.Dialog;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -137,6 +139,7 @@ import org.telegram.messenger.browser.Browser;
 import org.telegram.messenger.voip.VideoCapturerDevice;
 import org.telegram.messenger.voip.VoIPPendingCall;
 import org.telegram.messenger.voip.VoIPService;
+import org.telegram.onecric.ui.activity.CricketDetailActivity;
 import org.telegram.onecric.ui.activity.MatchActivity;
 import org.telegram.tgnet.ConnectionsManager;
 import org.telegram.tgnet.TLObject;
@@ -1544,6 +1547,41 @@ public class LaunchActivity extends BasePermissionsActivity implements ActionBar
         });
     }
 
+
+    private void handleNotification(Intent pintent) {
+//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//            // Create channel to show notifications.
+//            String channelId = getString(R.string.default_notification_channel_id);
+//            String channelName = getString(R.string.default_notification_channel_name);
+//            NotificationManager notificationManager =
+//                    getSystemService(NotificationManager.class);
+//            notificationManager.createNotificationChannel(new NotificationChannel(channelId,
+//                    channelName, NotificationManager.IMPORTANCE_LOW));
+//        }
+
+        // If a notification message is tapped, any data accompanying the notification
+        // message is available in the intent extras. In this sample the launcher
+        // intent is fired when the notification is tapped, so any accompanying data would
+        // be handled here. If you want a different intent fired, set the click_action
+        // field of the notification message to the desired intent. The launcher intent
+        // is used when no click_action is specified.
+        //
+        // Handle possible data accompanying notification message.
+        // [START handle_data_extras]
+        if (pintent.getExtras() != null) {
+//            for (String key : getIntent().getExtras().keySet()) {
+//                Object value = getIntent().getExtras().get(key);
+//                Log.d(TAG, "Key: " + key + " Value: " + value);
+//            }
+            Intent intent = new Intent();
+            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+            Bundle bundle = pintent.getExtras();
+            intent.setClass(this, CricketDetailActivity.class);
+            intent.putExtra("matchId", Integer.parseInt(bundle.getString("matchId")));
+            startActivity(intent);
+        }
+    }
+
     @SuppressLint("Range")
     private boolean handleIntent(Intent intent, boolean isNew, boolean restore, boolean fromPassword) {
         if (AndroidUtilities.handleProxyIntent(this, intent)) {
@@ -4660,6 +4698,9 @@ public class LaunchActivity extends BasePermissionsActivity implements ActionBar
     public void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
         handleIntent(intent, true, false, false);
+        if (intent.getExtras() != null) {
+            handleNotification(intent);
+        }
     }
 
     @Override