2017-11-25 33 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); 

       } 
相關問題