How do i associate a Device token with a User for Push Notifications

Hi Mark,
I’m trying to setup push notifications that are generally sent from one device to another. I have followed all steps in your documents and am able to send pushes using the console.
How do I associate a device token within the User Table.
How do I manage users having more than one device?
How do I get a notification(alert) if the user is currently in the app.
Also, could you please help me get rid of the warning in the image?
Thanks

Hi Mike,

Upon successful device registration the method returns device registration id. This is the ID you can use in the singlecast option when publishing a push notification. To associate device registration with a user, you can simply set the ID you get back from the registerDevice call into a custom user property. Alternatively, you could create a table called DeviceRegistration which would contain a reference to a user and his device registration ID.

I am not sure I understand the question about getting an alert if the user is logged in. It sounds like something that should be handled within the application itself.

As for the error in the screenshot, what is the reason you’re assigning a value to pushReceiver?

Mark

Hey Mark,

Thank you for your response. For questions 1 and 2, do you have any examples/sample/tutorial for the same?
For question 3, if the user is currently using the app, I see no notification and was wondering how to identify that a push is received.

As for the error, I was trying to follow the sample code at

Thank you.

Hi Mike,

For (1) and (2) it simply is a matter of getting the return value from the registerDevice call and then using the property update on the BackendlessUser object. It is very straight-forward.

For (3), take a look at this sample:

Here on line 46 the class declares itself as push receiver, meaning it will be notified when pushes arrive:

Then it declares delegates to handle actual notifications:

Hope this helps.

Mark

Thanks Mark,

Really helpful. Alerts work perfectly.
Still in the process of associating the DeviceID to a user. I will let you know how it goes.
Which one do you think should be used. Device ID or Device Token. Both of them have different values.

If the goal is to send push notifications to specific users, you should use device ID.

were you able to get that done? i can’t seem to retrieve my device id.
I tried this while doing the registeration of the device :
Backendless.Messaging.registerDevice(ProjectNumberNotification, “default”, new AsyncCallback<Void>() {
@Override
public void handleResponse(Void response) {
Log.d(TAG, "Device Registered for backendless messaging and push notifications. " );
String Device_ID = Backendless.Messaging.getDeviceRegistration().getDeviceToken();

    Log.d(TAG,"The Device ID is :  "+Device_ID);
}

@Override
public void handleFault(BackendlessFault fault) {
    Log.d(TAG, "Device Not Registered .  The Cause :   " + fault.getMessage()+fault.getCode()+fault.getDetail()+fault.getClass() );
}

});
Am i doing anything wrong?

Sorry for the trouble i’ve already found the solution :slight_smile: