[英]How to display date and time in notification?
When user finish select the date and time and press the button, the notification will send for user but how can i display the date and time in the notification? 当用户完成选择日期和时间并按下按钮时,通知将发送给用户,但是如何在通知中显示日期和时间?
My Firebase Data 我的Firebase数据
private void Confirm() {
String Doctor = mySpinner.getSelectedItem().toString();
myRef.child("Appointment").child(userID).child("Doctor").setValue(Doctor);
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notification.setSmallIcon(R.drawable.ic_stat_name);
notification.setTicker("This is the ticker");
notification.setWhen(System.currentTimeMillis());
notification.setContentTitle("Appointment");
notification.setContentText("Notification");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
String[] dates = new String[3];
dates[0] = "Date :" ;
dates[1] = "Time :" ;
dates[2] = "Doctor :" + Doctor;
inboxStyle.setBigContentTitle("Appointment");
for (String mDate : dates)
{
inboxStyle.addLine(mDate);
}
notification.setStyle(inboxStyle);
nm.notify(0,notification.build());
This is how i store my time and date data: 这是我存储时间和日期数据的方式:
String time = new StringBuilder().append(hourOfDay).append(':').append(minutes).append("").append(timeSet).toString();
theTime.getText().toString();
theTime.setText(time);
myRef.child("Appointment").child(userID).child("Time").setValue(time);
String date = (i1 + 1) + "/" + i2 + "/" + i;
Log.d(TAG, "onSelectedDayChange: date: " + date);
Intent intent = new Intent(CalendarActivity.this, Appointment.class);
intent.putExtra("date", date);
myRef.child("Appointment").child(userID).child("Date").setValue(date);
startActivity(intent);
To get the date and time, please use the following code: 要获取日期和时间,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference myRef = rootRef.child("Appointment").child(userID);
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String date = ds.child("Date").getValue(String.class);
String time = ds.child("Time").getValue(String.class);
//add date and time to notification
Log.d("TAG", data + " - " + time);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
youmyRefrRef.addListenerForSingleValueEvent(eventListener);
You outout will be: 您的出局将是:
10/31/2017 - 6:21AM
Remember to use the date
and time
only inside the onDataChange()
method otherwise will always be null, due the asyncronious behaviour of this method. 请记住,仅在
onDataChange()
方法内部使用date
和time
否则由于此方法的异步行为,该date
和time
将始终为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.