Ich möchte Detailaktivität auf Benachrichtigung Klickereignis öffnen. Hier ist die PendingIntent
und Notification
eingestellte Klasse. Ich fügte hinzu addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
auch PendingIntent.FLAG_UPDATE_CURRENT
hinzugefügt. Ich suchte alle Themen vor Ort, ich fand diese Lösungen, die ich alle versuchte. HierPendingIntent funktioniert nicht mit FCM-Benachrichtigung
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO(developer): Handle FCM messages here.
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
ArrayList<String> notificationData = new ArrayList<String >(remoteMessage.getData().values());
String fortuneID = notificationData.get(0);
sendNotification(remoteMessage.getNotification().getBody(),fortuneID);
}
// [END receive_message]
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody,String notificationID) {
Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class);
configureIntent.putExtra("extra", "123123");
configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
configureIntent.setAction("dummy_unique_action_identifyer" + "123123");
int dummyuniqueInt = new Random().nextInt(543254);
PendingIntent pendingClearScreenIntent = PendingIntent.getBroadcast(getApplicationContext(), dummyuniqueInt, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("myApp")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingClearScreenIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}
}
ist der getBundle
Teil MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String quote = getIntent().getStringExtra("extra");
...
}
Ein weiteres Problem, das ich will FalDetailActivity
öffnen, aber immer offen MainActiviy
und getIntent()
immer null zurück. Wahrscheinlich, meine PendingIntent
nicht gesetzt, ich habe keinen Fehler gefunden, bitte überprüfen Sie diesen Code. Dank ...
UPDATE
ich getBroadcast
-getActivity
aktualisieren und entfernen Sie etwas
Intent configureIntent = new Intent(getApplicationContext(), FalDetayActivity.class);
configureIntent.putExtra("extra", "123123");
configureIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingClearScreenIntent = PendingIntent.getActivity(getApplicationContext(), 0, configureIntent, PendingIntent.FLAG_UPDATE_CURRENT);
** configureIntent.setAction ("dummy_unique_action_identifyer" + "123123"); ** versuchen, diese Zeile und den Versuch zu entfernen. –
entfernte ich noch nicht –
arbeiten statt mit ** PendingIntent.getBroadcast() ** Nutzung ** PendingIntent.getActivity() ** –