Open ItamarShDev opened 8 years ago
I'm also looking for answer
Actually, the following works.
String regId = InstanceID.getInstance(context)
.getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE);
Are you sure you've set up your _SENDERID constant properly? Its value should be your project's "Project number" which you can find in your Cloud Console.
Ok, it works, but how to register device with this token to RegistrationEndpoint Api ?
You need to "build" an instance of it, then call the API's registerDevice() (or whatever you named the registration method). I believe it's also best to do so in an AsyncTask.
Here's an example implementation
RegistrationApi.Builder builder = new RegistrationApi.Builder(AndroidHttp.newCompatibleTransport(),
new AndroidJsonFactory())
// options for running against local devappserver
// - 10.0.2.2 is localhost's IP address in Android emulator
// - turn off compression when running against local devappserver
.setRootUrl("http://10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end options for devappserver
builder.setApplicationName(APP_NAME);
RegistrationApi registrationApi = builder.build();
try {
registrationApi.registerDevice(regId).execute();
} catch (IOException e) {
Log.e(TAG, e.getMessage());
}
From the docs it says to replace
with this:
Edit: nvm this doesn't work. This first method although deprecated will allow device to receive msgs, but the 2nd method won't. So I must be doing something wrong here..