[英]Activity TextView Doesn't shows what is in Firebase and Push notification only works inside activity?
I'm having a big or little problem, I want to show the specific message por each of my orders put it takes one and print it for the three of them and the push notification appears when I open the activity here is my code from java and xml 我有一个大问题或小问题,我想显示每个订单的具体消息,每个订单要花一个,然后为三个订单打印它,当我打开活动时出现推送通知,这是我来自Java的代码和xml
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());
}
});
}
}
This is the layout code: 这是布局代码:
<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" />
I add this to my code and it worked It's only missing the push notification outside the activity 我将其添加到我的代码中,并且可以正常工作,只是在活动之外缺少推送通知
if (detail.getUidrequest().equals(item.getUidrequest())){ 如果(detail.getUidrequest()。equals(item.getUidrequest())){
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.