简体   繁体   English

Activity TextView不显示Firebase中的内容,而Push通知仅在活动内部有效?

[英]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.

相关问题 单击通知不会打开提到的活动 - Clicking on notification doesn't open mentioned activity 当我点击通知推送时,特定活动无法打开(需要真正的帮助) - When i push notification clicked, specific activity doesn't open (need really help) 如何打开新活动并通过单击Firebase通知在textview上打印通知消息 - How open a new activity & print the notification message on a textview by clicking on firebase notification 推送通知打开一个新活动 - Push notification open a new activity 在推送推送通知时解析推送“未找到活动” - Parse Push “No Activity Found” on opening Push Notification 单击带有Firebase的通知时打开通知活动 - Open Notification activity when clicked on Notification with firebase 点击通知后,新活动将无法开始 - Upon clicking notification, new activity doesn't start Android活动仅在主要活动下才能正常运行吗? - Android activity only works properly if it is the main activity? 仅在未显示活动时显示通知 - Show a notification only if Activity is not showing 在广播接收器中起作用的代码在活动中不起作用 - Code that works in Broadcast Receiver doesn't work in Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM