Android12以上だとpush通知受信でクラッシュする




```
2022-03-10 11:12:43.765 1360-2196/? E/HwDetectorWithState: a: 3
2022-03-10 11:13:03.322 364-364/? E/android.hardware.power.stats@1.0-service-mock: Failed to getEnergyData
2022-03-10 11:14:00.148 10586-10824/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx E/AndroidRuntime: FATAL EXCEPTION: Firebase-Messaging-Intent-Handle
    Process: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx, PID: 10586
    java.lang.IllegalArgumentException: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
        at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
        at android.app.PendingIntent.getActivity(PendingIntent.java:444)
        at android.app.PendingIntent.getActivity(PendingIntent.java:408)
        at xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.MyFirebaseMessagingService.sendNotification(MyFirebaseMessagingService.java:133)
        at xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.MyFirebaseMessagingService.onMessageReceived(MyFirebaseMessagingService.java:68)
        at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(com.google.firebase:firebase-messaging@@21.0.1:13)
        at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(com.google.firebase:firebase-messaging@@21.0.1:8)
        at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(com.google.firebase:firebase-messaging@@21.0.1:3)
        at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(com.google.firebase:firebase-messaging@@21.0.1:3)
        at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(Unknown Source:1)
        at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(Unknown Source:6)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.3.0:6)
        at java.lang.Thread.run(Thread.java:920)
2022-03-10 11:14:00.681 393-393/? E/BpTransactionCompletedListener: Failed to transact (-32)
2022-03-10 11:14:57.758 1034-10816/? E/Volley: [612] cmw.b: Unexpected response code 400 for https://notifications-pa.googleapis.com/v1/gmscore/legacy/fetchbyidentifier?alt=proto
2022-03-10 11:14:58.487 1034-10816/? E/Volley: [612] cmw.b: Unexpected response code 400 for https://notifications-pa.googleapis.com/v1/gmscore/legacy/fetchbyidentifier?alt=proto
2022-03-10 11:14:59.220 1034-10816/? E/Volley: [612] cmw.b: Unexpected response code 400 for https://notifications-pa.googleapis.com/v1/gmscore/legacy/fetchbyidentifier?alt=proto
2022-03-10 11:14:59.723 1034-10939/? E/GunsFetchByIdentifierOp: GunsFetchByIdentifierOperation failed to fetch notification by identifier. Reached maximal number of retries 3. [CONTEXT service_id=110 ]
2022-03-10 11:15:03.316 364-364/? E/android.hardware.power.stats@1.0-service-mock: Failed to getEnergyData

```

# 修正内容

## gradle修正
```diff
-implementation 'com.google.firebase:firebase-messaging'
+implementation 'com.google.firebase:firebase-messaging:23.0.0'
```

## Token取得修正
FirebaseInstanceIdが使えなくなったので、FirebaseMessagingへ変更

```diff_java
-	FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
+	FirebaseMessaging.getInstance().getToken().addOnCompleteListener(new OnCompleteListener<String>() {

-		String token = task.getResult().getToken();
+		String token = task.getResult();
```

## 通知タップのPendingIntentのところ修正

> インテントの安全でない起動
> Android 12 以降では、プラットフォームのセキュリティを強化するため、インテントの安全でない起動を検出するデバッグ機能が導入されました。このような安全でない起動がシステム> によって検出されると、StrictMode 違反が発生します。

ということなので、FLAGを変更。

```diff_java
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
-				PendingIntent.FLAG_ONE_SHOT);
+				PendingIntent.FLAG_IMMUTABLE);
```