GCMRegistrar.register
is an asynchronous method. If you choose to use it, you can get the response via a broadcast receiver. GCMRegistrar.getRegistrationId
returns a non empty value only after the first time your app gets a response to the registration request.
However, that class is deprecated. You are encouraged to use GoogleCloudMessaging.register
instead, which is synchronous, and therefore shouldn't be run on the main thread.
You can see code samples in the official GCM guide.