2017-10-27 8 views
0

ユーザーが日付と時刻を選択してボタンを押すと、通知がユーザーに送信されますが、通知に日付と時刻をどのように表示できますか?通知の日時を表示する方法は?

マイFirebaseデータ

My Firebase Data

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()); 

これは私が私の時間と日付のデータを格納する方法である:

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); 

答えて

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); 
あなたはoutout

は次のようになります。

10/31/2017 - 6:21AM 

のみonDataChange()メソッドの内部datetimeを使用することを忘れないでくださいそれ以外の場合は、常にこの方法のasyncronious行動により、nullになります。

関連する問題