1

I want to send device Token information when sending membership information to server.

But how should I go because getToken is no longer in use?

I've been using this before:

params.put("deviceToken", FirebaseInstanceId.getInstance().getToken());

Easy and worked but getToken is deprecated

}, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, "Registration Error: " + error.getMessage());
            Toast.makeText(getApplicationContext(),
                    error.getMessage(), Toast.LENGTH_LONG).show();
            hideDialog();
        }
    }) {

        @Override
        protected Map<String, String> getParams() {
            // Posting params to register url
            Map<String, String> params = new HashMap<String, String>();
            params.put("name", name);
            params.put("email", email);
            params.put("password", password);
            params.put("deviceToken", deviceTokenID); <<<---- DEVICE ID TOKEN

            return params;
        }

    };

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

2 Answers2

1

To solve this, you need to use a success listener like in the following lines of code:

FirebaseInstanceId.getInstance().getInstanceId()
    .addOnSuccessListener(new OnSuccessListener<InstanceIdResult>() {
        @Override
        public void onSuccess(InstanceIdResult instanceIdResult) {
            String tokenId = instanceIdResult.getToken();
            //Do what you need to do with the token
        }
});
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • I've seen your shared code on many websites but I can't use it. How can I add this into `params.put`? I can't do because my Java knowledge is not good – JavaOgreniyor Nov 27 '18 at 17:27
  • Your question is: "How get Firebase Device Token like string?" at which I have already provided an answer. This is another problem which is beyond the scope of this question. Please ask another question that explains the problem, and what you've tried already to solve it, so me and other users can help you. – Alex Mamo Nov 27 '18 at 17:39
0
 String deviceToken= FirebaseInstanceId.getInstance().getToken();
 params.put("deviceToken", deviceToken);
Anand
  • 1,866
  • 3
  • 26
  • 49