2017-11-25 78 views
0

我有一个很大或很小的问题,我想显示具体的消息por我的每个订单把它需要一个,并为他们三个打印它,当我打开这里的活动时出现推送通知是我的代码从Java和XML活动TextView不显示Firebase中的内容,推送通知仅在活动中起作用?

public class MessageActivity extends AppCompatActivity { 

    public TextView message; 
    private DatabaseReference mDatabase; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_message); 

     mDatabase = FirebaseDatabase.getInstance().getReference().child("users").child("paid").child(FirebaseAuth.getInstance().getCurrentUser().getUid()); 

     message = findViewById(R.id.message); 
     mDatabase.addValueEventListener(new ValueEventListener() { 
      @Override 
      public void onDataChange(DataSnapshot dataSnapshot) { 
       for (DataSnapshot areaSnapshot : dataSnapshot.getChildren()) { 
        DetailCart detail = areaSnapshot.getValue(DetailCart.class); 
        String mess = detail.getMessage(); 
        message.setText(mess); 
        NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
        Notification notify=new Notification.Builder 
          (getApplicationContext()).setContentTitle(mess).setContentText(mess). 
          setContentTitle(mess).setSmallIcon(R.drawable.ic_person).build(); 
        notify.flags |= Notification.FLAG_AUTO_CANCEL; 
        notif.notify(0, notify); 
       } 
      } 

      @Override 
      public void onCancelled(DatabaseError databaseError) {  
       // [START_EXCLUDE] 
       System.out.println("The read failed: " + databaseError.getMessage()); 
      } 
     }); 
    } 
} 

这是布局代码:

<TextView 
    android:id="@+id/message" 
    android:textSize="20dp" 
    android:layout_marginBottom="5dp" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Message" 
    android:textColor="@android:color/holo_blue_dark" 
    android:textColorHighlight="@android:color/primary_text_dark" /> 

回答

0

我加入这个我的代码和它的工作它唯一缺少的推送通知活动

如果(细节之外。 getUidrequest()。等于(item.g etUidrequest())){

    String mess = detail.getMessage(); 
        message.setText(mess); 
        NotificationManager notif=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); 
        Notification notify=new Notification.Builder 
          (getApplicationContext()).setContentTitle(mess).setContentText(mess). 
          setContentTitle(mess).setSmallIcon(R.drawable.ic_person).build(); 
        notify.flags |= Notification.FLAG_AUTO_CANCEL; 
        notif.notify(0, notify); 

       }