Ich versuche eine Aktivität zu starten, indem ich auf eine Benachrichtigung klicke, aber das funktioniert nur, wenn ich bereits in der App bin.Starten einer Aktivität beim Klicken auf eine Benachrichtigung
Hier ist der Code, den ich denke, mit ihm zu tun hat:
private void sendNotification(String body) {
Intent intent = new Intent(ImpFirebaseMessagingService.this, codeActivity.class);
intent.putExtra("body", body);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri notificationSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Implementation TFA")
.setContentText(body)
.setAutoCancel(true)
.setSound(notificationSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
Wird dieser Code in einem Dienst geschrieben? – shadygoneinsane
@shadygoneinsane Ich folgte einem Tutorial und ich denke schon, weil die Datei MyFirebaseMessagingService heißt –