我是 kotlin 的新手,当我阅读 kotlin 中的数据类时,我发现了这些代码。它基本上是 java 模型类和 kotlin 数据类之间的比较,并且写在那里,两个代码都执行相同的任务。
代码1
public class VideoGame {
private String name;
private String publisher;
private int reviewScore;
public VideoGame(String name, String publisher, int reviewScore) {
this.name = name;
this.publisher = publisher;
this.reviewScore = reviewScore;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public int getReviewScore() {
return reviewScore;
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 fcm 在我的应用程序中推送通知,但是当应用程序关闭并从最近的应用程序中清除时,通知不会出现。我可以使用 FCM api 将通知发送到特定主题。注意:- 当应用程序在后台时,通知工作正常
这是我的 FirebaseMessagingService 代码
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
Map<String, String> extraData = remoteMessage.getData();
Log.d("DATA",remoteMessage.getData().toString());
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, "TAC")
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ic_launcher_background);
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int id = (int) System.currentTimeMillis();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
NotificationChannel channel = new NotificationChannel("TAC","demo",NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(channel);
}
notificationManager.notify(id,notificationBuilder.build());
}
Run Code Online (Sandbox Code Playgroud)
}
这是通知发送者类代码
公共类通知发送者{
public static RequestQueue mRequest;
public static String URL="https://fcm.googleapis.com/fcm/send";
public static void sendnotification(Context …Run Code Online (Sandbox Code Playgroud) android firebase firebase-cloud-messaging firebase-notifications