我想在点击通知时打开一个特定的Android活动,但问题是当我点击我的通知时打开我的MainActivity但是例如我想要打开我的活动,名为Notificacion.class,我使用了google的firebase,这是我的代码。
public class MyfirebaseMessagingService extends FirebaseMessagingService{
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//final Intent intent = new Intent(this, Notificacion.class);
//startActivity(intent);
Intent intent = new Intent(this, Notificacion.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("Sección 15");
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notificationBuilder.setSound(defaultSound);
long[] pattern = new long[]{1000,500,1000};
notificationBuilder.setVibrate(pattern);
notificationBuilder.setSmallIcon(R.drawable.logo);
notificationBuilder.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0,notificationBuilder.build());
}
}
答案 0 :(得分:1)
在此行中替换您的活动的“Notificacion.class”:
Intent intent = new Intent(this, Notificacion.class);
看起来应该是这样的:
Intent intent = new Intent(this, MyActivity.class);
答案 1 :(得分:0)
您创建并传递给待处理Intent的意图是在您单击通知时使用的意图,因此将您想要打开的Activity放入intent中,您还可以向intent添加额外数据并通过获取intent来检索它们getIntent()