导航菜单

页面标题

页面副标题

FMG v6.0 - PushNotificationService.java 源代码

正在查看: FMG v6.0 应用的 PushNotificationService.java JAVA 源代码文件

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


package it.icontact.android.pdf2ipad.irisfmg.pn;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import androidx.core.app.NotificationCompat;
import com.google.firebase.messaging.Constants;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import it.icontact.android.pdf2ipad.irisfmg.App;
import it.icontact.android.pdf2ipad.irisfmg.R;
import it.icontact.android.pdf2ipad.irisfmg.view.main.MainActivity;
import org.apache.commons.lang3.RandomUtils;
import timber.log.Timber;

public class PushNotificationService extends FirebaseMessagingService {
    public static final String CHANNEL_NOTIFICHE = "NOTIFICHE";

    @Override
    public void onNewToken(final String token) {
        super.onNewToken(token);
        Timber.i("Got new PN token: %s", new Object[]{token});
        ((App) getApplication()).pnUpdateDeviceTokenOnServer();
    }

    @Override
    public void onMessageReceived(final RemoteMessage m) {
        super.onMessageReceived(m);
        Timber.i("Received message: %s", new Object[]{m});
        if (m == null || m.getNotification() == null) {
            return;
        }
        NotificationCompat.Builder defaults = new NotificationCompat.Builder(this, CHANNEL_NOTIFICHE).setSmallIcon(R.drawable.ic_pn).setContentTitle(m.getNotification().getTitle()).setContentText(m.getNotification().getBody()).setAutoCancel(true).setDefaults(-1);
        Intent intent = new Intent(this, (Class<?>) MainActivity.class);
        intent.putExtra(Constants.MessagePayloadKeys.MSGID, m.getMessageId());
        intent.addFlags(67108864);
        defaults.setContentIntent(PendingIntent.getActivity(this, 0, intent, 201326592));
        NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
        if (notificationManager != null) {
            int nextInt = RandomUtils.nextInt(0, Integer.MAX_VALUE);
            if (m.getData() != null && m.getData().containsKey("id")) {
                try {
                    nextInt = Integer.parseInt(m.getData().get("id"));
                } catch (NumberFormatException unused) {
                }
            }
            notificationManager.notify(nextInt, defaults.build());
        }
    }
}