ich dort bin mit Feuerbasis kann ich sehen, wenn ein neues „Kind“ hinzugefügt wird, ich eine Benachrichtigung zeigen müssen, wenn ein neues Kind hinzugefügt wird ich diesen Code verwende, aber es funktioniert nichtWie zeigen Sie Benachrichtigungen an, wenn der Benutzer nicht mehr in der App ist?
(Die Benachrichtigungen arbeiten zeigt aber nur in einer Aktivität, muss ich die Benachrichtigung angezeigt, wenn der Nutzer aus der App ist, wie Facebook oder whatsapp
Methode:
public Notification createNotification(boolean makeHeadsUpNotification) {
Notification.Builder notificationBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_settings_real_black_24dp)
.setPriority(Notification.PRIORITY_DEFAULT)
.setContentTitle("Sample Notification")
.setContentText("This is a normal notification.");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setCategory(Notification.CATEGORY_MESSAGE);
}
if (makeHeadsUpNotification) {
Intent push = new Intent();
push.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
push.setClass(this, UserActivity.class);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
push, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder
.setContentText("Heads-Up Notification on Android L or above.")
.setFullScreenIntent(fullScreenPendingIntent, true);
}
return notificationBuilder.build();
}
// Methode für Benachrichtigungen, wenn Kind hinzugefügt wird
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// THIS METHODS ARE IN THE ONCREATE
mListener = FirebaseUtils.getCHATSOLICITUDRef("8HaKY67AjaOD2a6QKrABhR2rcaJ3").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
/// THE METHOD IS IN THIS
mNotificationManager.notify(1, createNotification(
true));
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Wie Sie es implementieren überprüfen? Ich erstelle die Klasse und lege sie in das Manifest und das war's? und das zeigt, wenn Benutzer die App aus? @Oussema Aroua –
Ja einfach so –
Wie stellst du das Manifest ein? –