Push notification between two emulators

Hi, I’ve been trying to send a message between two emulators(both Genymotion) but I can’t do it because at the moment of retrieving the registration for push notification I always get “Unkown device Id”. Then I can register the first emulator but when i try to register the second I get the handle response(so I guess all is fine) but when i see the device registered in the console I only see one (the first). Googling I found you use Serial Number of the device as device ID but in my case both serial number in the Genymotion emulators are “unknown” so I guess that is the problem.

My question is: Is it possible that in the next update we can use emulators for test messaging. I think is simple,in the code:

String id=Build.Serial; 
if (id==null || id==""){.....

Just Add:

String id=Build.Serial; 
if (id==null || id=="" ||  id.matches("unknown")){.....

Thanks for your supporting.

Hi SamuelC,

We just pushed a change that will give you the flexibility to assign a custom device ID. You can download the build from here:
https://github.com/Backendless/Android-SDK/tree/master/out

I would recommend using the following code to generate a unique device id:

StringBuilder builder = new StringBuilder();
builder.append( System.getProperty( "os.name" ) );
builder.append( System.getProperty( "os.arch" ) );
builder.append( System.getProperty( "os.version" ) );
builder.append( System.getProperty( "user.name" ) );
builder.append( System.getProperty( "java.home" ) );
com.backendless.Messaging.DEVICE_ID = UUID.nameUUIDFromBytes( builder.toString().getBytes() ).toString();

Notice the code references the following variable:
com.backendless.Messaging.DEVICE_ID

It is important to assign a custom device ID before you call the registerDevice method.

Hope this helps.

Regards,
Mark

Hi Mark,

It works perfect. I use this code(because both emulators are cloned from the same virtual device in genymotion so both get the same deviceId with your code):

private void loadId(){
settings sett=new settings();
List<settings> sett1=sett.loadFromLocalWHERE(null,null,null,null,null);
String Id=null;if (sett1.size()>0)sett=sett1.get(0);Id=sett.getDeviceId();
if (Id==null || Id.matches("")){
StringBuilder builder = new StringBuilder();
builder.append( System.getProperty( "os.name" ) );
builder.append( System.getProperty( "os.arch" ) );
builder.append( System.getProperty( "os.version" ) );
builder.append( System.getProperty( "user.name" ) );
builder.append( System.getProperty( "java.home" ) );
builder.append( new Random().nextInt(100000 - 0) );
Id=UUID.nameUUIDFromBytes( builder.toString().getBytes() ).toString();
sett.setDeviceId(Id);
sett.saveInLocal();
}
com.backendless.Messaging.DEVICE_ID = Id;
}

Thanks for your support.

Hi SamuelC,

I am trying to set emulator device id for two emulators cloned from the same virtual device same as you but cannot understand your code.

What is settings? Is it a POJO Class? If so, then confirm that deviceId is one of the parameters because i can see setter and getter for the same.

The line

String Id=null;if (sett1.size()>)sett=sett1.get();Id=sett.getDeviceId();

sett1.size()> is greater than what?

Please also elaborate

sett.loadFromLocalWHERE(null,null,null,null,null);

and

sett.saveInLocal();

I would really appreciate in more exhaustive explanations you might offer.

Thanks,
George