2017-06-29 5 views
0

私は、新しい「子」が追加されたとき、私は新しい子は(通知が動作し、私はこのコードを使用していますが、それは?私はそこにfirebaseを使用しています

動作しない を追加された通知を表示する必要が見ることができますちょうど活動で、私は、ユーザーがFacebookのような、アプリの外にある場合や、通知を表示する必要があります示してのWhatsApp

方法:

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(); 
} 
子が追加された通知の

// METHOD

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) { 

     } 
    }); 




} 

答えて

1

あなたはどのようにあなたがそれを実装するのですまた、私のコードhere

+0

をチェックServicesので、それがバックグラウンドで動作します使用することができますか?私はクラスを作成してそれをマニフェストに入れるだけです。これはユーザーがアプリを出ているときを示していますか?あなたがマニフェストに入れてどのように@Oussema Aroua –

+0

はい、ちょうどそのような –

+0

? –

関連する問題