-1

I am trying to use the firebase FCM services to send notification to users. when a user logins, i store its token_id to the Firestore database.

this is how i store the token_id.

String token_id = FirebaseInstanceId.getInstance().getToken();
   Log.i("token_id",token_id);
   Map<String,Object>  tokenMap = new HashMap<>();
   tokenMap.put("token_id",token_id);
   mFireStore.collection("Users").document(current_id).update(tokenMap).addOnSuccessListener(new OnSuccessListener<Void>() {
              @Override
              public void onSuccess(Void aVoid) {
                 Toast.makeText(LoginActivity.this, "Signed in Successfully", Toast.LENGTH_SHORT).show();
                 startActivity(new Intent(LoginActivity.this,AdminActivity.class));
                 finish();
         }
  });

but when i login with the same user in different device, the previous token_id gets update with the new one..

is there any way that i can create a list of token_ids so that i can use it in the node.js function

AL.
  • 36,815
  • 10
  • 142
  • 281
rituparna
  • 91
  • 1
  • 12

1 Answers1

2

One thing that you could do is to change your Firestore schema to something like this:

/users (collection)
  /userId (document)
    /name (field)
    /otherStuff (fields)
    /pushTokens (collection)
      /deviceId (document)
        /token (field)

This way, you'd be able to put multiple tokens per user. Instead of a collection, you could also just use an array.

This would be very effective if you can find a good device id to pair the token. There used to be an ANDROID_ID value, but if I remember correctly, it's no longer advisable to use. Discussing how to handle device groups is a bit broad, so I would suggest looking at my answer here.

AL.
  • 36,815
  • 10
  • 142
  • 281