-2

In chat App how to implement Typing indicator that someone is Typing just like whats-app or Messenger in Android Studio using Firebase

as shown in the Figure

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Arsalan
  • 23
  • 2
  • 9

1 Answers1

7

To achieve this, you need add a new field in your Firebase database named: typing with the default value of false. Then use addTextChangedListener() method on your EditText to actually see when someone types a message. When someone types something, onTextChanged() method is triggered. Now change the value of typing from false to true. After this, addValueEventListener to see when the value is changed. If the value is true, then display that message in your chat room. So, i suggest you using the following code:

yourEditText.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (!TextUtils.isEmpty(s)) {
            //Set the value of typing field to true.
        } else {
            // Set to false
        }
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    @Override
    public void afterTextChanged(Editable s) {}
});
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I need one more help how to update isTyping in database when someOne is Typing my database hierarchy as shown: https://firebasestorage.googleapis.com/v0/b/websolutionseo-8c349.appspot.com/o/Capture.PNG?alt=media&token=3f78dfc5-ec33-40d1-af19-e0853d0f2b5c – Arsalan Aug 28 '17 at 13:30
  • Will you please provide me a piece of code to understand this.How to implement typing features in android – Rahul Kushwaha Dec 18 '18 at 08:50
  • If the typing field was true during the writing and the user left the app and failed to connect with Firestore to update it to false what will happen, What is the best practice to avoid this scenario? – Taha Sami Oct 02 '21 at 10:52
  • 1
    @muco2 You might also consider reading [this](https://firebase.google.com/docs/perf-mon/app-start-foreground-background-traces?platform=android). – Alex Mamo Oct 02 '21 at 11:01