我想打開一個特定的android活動,當我點擊一個通知,但問題是,當我點擊我的notifiation這打開我的MainActivity,但例如,我想打開我的活動叫做Notificacion.class,我使用了google的firebase,這是我的代碼。如何打開一個android活動,當我點擊一個通知
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());
}
}
我實際上已經嘗試過你的代碼,它顯示了我想要的活動。我可以給你幾條標準的建議: - 檢查清單,如果期望的活動存在 - 嘗試使用context.getApplicationContext() – thekekc