我有一个类Home.java
,当我打开应用程序以检查用户是否登录时,它首先运行。
public class Home extends Application { @Override public void onCreate() { super.onCreate(); FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); FirebaseUser firebaseUser = firebaseAuth.getCurrentUser(); if (firebaseUser != null) { Intent intent = new Intent(getApplicationContext(), HomeActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } } }
我面临的问题是,当我收到此应用的通知时,它是从LogIn活动而不是HomeActivity开始的。我知道,如果要从通知中打开特定活动,则需要在启动器活动中指定getIntent(),但是我没有任何启动器活动。当我尝试在Home.java类中实现getIntent()时,该方法未导入,因为它没有扩展Activity类。任何帮助!
NotificationService.java
public class NotificationService extends FirebaseMessagingService {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, "Restaurants")
.setContentTitle(title)
.setContentText(body)
.setSmallIcon(R.drawable.ic_launcher_background)
.setSound(uri); //applying default notification sound to the notification
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
int id = (int) System.currentTimeMillis();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel notificationChannel = new NotificationChannel("Restaurants", "demo", NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
}
notificationManager.notify(id, notificationBuilder.build());
}
}
我有一个Home.java类,当我打开应用程序以检查用户是否登录时,它首先运行。公共类Home扩展应用程序{@Override public void onCreate()...
[当您想单击“通知”时打开一个活动,然后使用如下代码: