Reputation: 31
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);
Upvotes: 1
Views: 351
Reputation: 1959
String deviceToken= FirebaseInstanceId.getInstance().getToken();
params.put("deviceToken", deviceToken);
Upvotes: 0
Reputation: 139019
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
}
});
Upvotes: 1