java - 无法运行远程消息
问题描述
package Service;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import androidx.core.app.NotificationCompat;
import com.ablut.yummycakesug.MainActivity;
import com.ablut.yummycakesug.R;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
public class MyFirebaseMessaging extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage remoteMessage) {
RemoteMessage.Notification notification = remoteMessage.getNotification();
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent= PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(notification.getTitle())
.setContentText(notification.getBody())
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager noti =(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
noti.notify(0,builder.build());
}
}
错误如下
C:\Users\ABDULSALAAM\AndroidStudioProjects\YummyCakesUG3\app\src\main\java\Service\MyFirebaseMessaging.java:26:错误:无法访问 zza RemoteMessage.Notification notification = remoteMessage.getNotification(); ^ com.google.android.gms.common.internal.safeparcel.zza 的类文件未找到
解决方案
推荐阅读
- reactjs - react-select 2下没有空间时如何有条件地在顶部显示项目
- visual-studio-code - Visual Studio Code - 使用制表键缩进单行
- delphi - Delphi 动态创建 ADOStoredProcedure 参数
- java - html + Java | 从输入类型 =“时间”接收 0
- keycloak - 无法通过 keycloak admin api 注册预期的密码盐值
- r - 如何从包含 R 中的字符串元素的列表中创建变量?
- javascript - 将 Angular4 中的 [ngStyle] 绑定到 ngModel 或 2 路绑定
- elasticsearch - 在 PCF 抛出错误中创建的 Syslog Drain
- logstash - filebeat.yml.rpmnew 或 filebeat.yml
- typescript - 通过 Typescript / VS Code 导入建议