Support Topics Documentation Slack YouTube Blog

Get device id by mobile phone

Hello
How to get Device id from a DeviceRegistration table for a mobile number?
user mobile number is Ration to DeviceRegistration column.
I wanna send the mobile number to server and get deviceRegistration deviceId value for use push notification

Hi @saeed_noshadi

I’m not sure that I understood you correctly. We would need more details in order to help. What do you mean by “get Device id from a DeviceRegistration table for a mobile number”?
Please tell more about the scenario

Anton

Also notice, that Backendless sdk doesn’t automatically send on the server side phone number. You need to implement this logic by yourself.

i want send notification to specify user.
I don’t know how to get the user device number that was entered and send it a notification

If you are talking about getting deviceId then we are getting deviceId in our SDK from the device itself. This can be done in a few methods depending on the platform (iOS, Android. You can google it). Here is an example for Android - https://stackoverflow.com/questions/2785485/is-there-a-unique-android-device-id

BUT in cases if there are problems with getting unique identifier - we are generating random ID. That’s why you should not rely directly on device’s id.

What I suggest is to implement logic on client side in a way, that deviceRegistration API is always called by authenticated (logged in) users. This will automatically establish relation between a user and device - https://monosnap.com/file/Y64QoEjBwXrn6foNDqd7MNNcAmUEkm

In this case you will always be able to target any device belonging to any specific user. In order to find required device - run query against DeviceRegistration table:

  DataQueryBuilder queryBuilder = DataQueryBuilder.create();
  queryBuilder.setWhereClause("user.objectId = 'A93F5CF4-DDD0-3BE2-FF8B-13BCE9571E00'");
  Backendless.Data.of("DeviceRegistration").find(queryBuilder, new AsyncCallback<List<Map>>() {
                @Override
                public void handleResponse(List<Map> response) {
                    System.out.println(response);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    System.out.println(fault);
                }
            });

Instead of objectId it could be email or any other query you prefer. In result you will get a list of Maps (DeviceRegistration objects) which satisfy the query you added, each resulting Map will contain deviceId and all other properties of DeviceRegistration instance.
To schedule a push notification to specific devices - see the following docs.

Anton

The user in the Users table is associated with one of the rows in the DeviceRegistration table. I want to send my mobile number to the Users table and return my deviceID which exist in DeviceRegisteration table.
when i get deviceId in that time send push notification to that

Backendless has no API’s to get device’s phone number. You should prompt users to update their account with phone number and to update User records with this value, or google how to achieve this in general “how to?” forums like stackoverflow.

Regarding your GET request. You should query your DeviceRegistration table. Backward scenario is impossible.

Request would be:

DataQueryBuilder queryBuilder = DataQueryBuilder.create();
queryBuilder.setWhereClause("user.phoneNumber = '0123456789'");
Backendless.Data.of("DeviceRegistration").find(queryBuilder, new AsyncCallback<List<Map>>() {
                @Override
                public void handleResponse(List<Map> response) {
                    System.out.println(response);
                }

                @Override
                public void handleFault(BackendlessFault fault) {
                    System.out.println(fault);
                }
            });

Please see this line:
queryBuilder.setWhereClause("user.phoneNumber = '0123456789'");

This means you are searching for DeviceRegistration objects, which has relations to a user, the user should have phone number ‘0123456789’. In response handler you will get an array of objects matching the query. Each element in the returned collection will have deviceId property which can be used to send push notifications.

And underlining again: Backward scenario is impossible. You cannot query Users table in this case, request should be sent to DeviceRegistration table

Anton