当用户完成选择日期和时间并按下按钮时,通知将发送给用户,但如何在通知中显示日期和时间?
我的Firebase数据
$target_dir = "upload/";
if(isset($_POST['CopyImages']))
foreach ($_POST['photoselect'] as $photourl) {
$photoname= basename($photourl);
copy($photourl, $target_dir.'/'.$photoname);
}
}
这是我存储时间和日期数据的方式:
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());
答案 0 :(得分:0)
要获取日期和时间,请使用以下代码:
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);
你的出局将是:
10/31/2017 - 6:21AM
请记住仅在date
方法中使用time
和onDataChange()
,否则将始终为null,原因是此方法的异步行为。