导航菜单

页面标题

页面副标题

St.John's v1.0.9 - MyFirebaseMessagingService.java 源代码

正在查看: St.John's v1.0.9 应用的 MyFirebaseMessagingService.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.mcb.stjohnsemschool.notifications;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.mcb.stjohnsemschool.activity.SplashActivity;
import com.mcb.stjohnsemschool.utils.Constants;
import com.microsoft.identity.common.java.providers.microsoft.MicrosoftAuthorizationResponse;
import cz.msebera.android.httpclient.HttpHost;
import io.ably.lib.http.HttpConstants;
import io.ably.lib.push.ActivationContext;
import io.ably.lib.types.RegistrationToken;
import org.json.JSONException;
import org.json.JSONObject;

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMessagingService";
    boolean isLoggedIn = false;
    SharedPreferences mSharedPref;
    private NotificationUtils notificationUtils;

    public void onNewToken(String str) {
        super.onNewToken(str);
        SharedPreferences.Editor edit = getSharedPreferences("", 0).edit();
        ActivationContext.getActivationContext(this).onNewRegistrationToken(RegistrationToken.Type.FCM, str);
        edit.putString(Constants.REGISTER_ID, str);
        edit.putBoolean(Constants.ABLY_REGISTER_ID, true);
        edit.commit();
    }

    public void onMessageReceived(RemoteMessage remoteMessage) {
        String str = TAG;
        Log.e(str, "From: " + remoteMessage.getFrom());
        if (remoteMessage == null) {
            return;
        }
        if (remoteMessage.getNotification() != null) {
            Log.e(str, "Notification Body: " + remoteMessage.getNotification().getBody());
            handleNotification(remoteMessage.getNotification().getBody());
        }
        if (remoteMessage.getData().size() > 0) {
            Log.e(str, "Data Payload: " + remoteMessage.getData().toString());
            try {
                handleDataMessage(new JSONObject(remoteMessage.getData()));
            } catch (Exception e) {
                Log.e(TAG, "Exception: " + e.getMessage());
            }
        }
    }

    private void handleNotification(String str) {
        if (NotificationUtils.isAppIsInBackground(getApplicationContext())) {
            return;
        }
        Intent intent = new Intent(Config.PUSH_NOTIFICATION);
        intent.putExtra(MicrosoftAuthorizationResponse.MESSAGE, str);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
        new NotificationUtils(getApplicationContext()).playNotificationSound();
    }

    private void handleDataMessage(JSONObject jSONObject) {
        Log.e(TAG, "push json: " + jSONObject.toString());
        try {
            String string = getResources().getString(2131886124);
            String string2 = getResources().getString(2131886124);
            if (jSONObject.has("Title")) {
                string = jSONObject.getString("Title");
            }
            if (jSONObject.has(MicrosoftAuthorizationResponse.MESSAGE)) {
                string2 = jSONObject.getString(MicrosoftAuthorizationResponse.MESSAGE);
            }
            String string3 = jSONObject.has("type") ? jSONObject.getString("type") : "";
            String string4 = jSONObject.has("ImagePath") ? jSONObject.getString("ImagePath") : "";
            String string5 = jSONObject.has(HttpConstants.Headers.LINK) ? jSONObject.getString(HttpConstants.Headers.LINK) : "";
            if (string == null || string.length() == 0) {
                string = getResources().getString(2131886124);
            }
            Intent intent = new Intent(getApplicationContext(), (Class<?>) SplashActivity.class);
            if (string5 != null && string5.length() > 0 && !string5.equalsIgnoreCase("null") && string5.startsWith(HttpHost.DEFAULT_SCHEME_NAME)) {
                intent.putExtra(HttpConstants.Headers.LINK, string5);
            }
            intent.putExtra("type", string3);
            intent.setAction(Long.toString(System.currentTimeMillis()));
            SharedPreferences sharedPreferences = getSharedPreferences("", 0);
            this.mSharedPref = sharedPreferences;
            if (sharedPreferences.getBoolean(Constants.KEY_NOTIFICATION, false)) {
                showNotificationMessage(getApplicationContext(), string, string2, intent, string4, this.mSharedPref);
            }
        } catch (JSONException e) {
            Log.e(TAG, "Json Exception: " + e.getMessage());
        } catch (Exception e2) {
            Log.e(TAG, "Exception: " + e2.getMessage());
        }
    }

    private void showNotificationMessage(Context context, String str, String str2, Intent intent, String str3, SharedPreferences sharedPreferences) {
        NotificationUtils notificationUtils = new NotificationUtils(context);
        this.notificationUtils = notificationUtils;
        notificationUtils.showNotificationMessage(str, str2, intent, str3, sharedPreferences);
    }
}