Here i got another problem regarding the push notification,it works perfectly in emulator but not working in device.
code:for the GCMIntentService
public class GCMIntentService extends GCMBaseIntentService{
public GCMIntentService(){
super(Constants.SenderId);
}
#Override
protected void onError(Context context, String regId) {
// TODO Auto-generated method stub
System.out.println("insideerroe");
Log.e("", "error registration id : "+regId);
}
#Override
protected void onMessage(Context context, Intent intent) {
// TODO Auto-generated method stub
}
#Override
protected void onRegistered(Context context, String regId) {
// TODO Auto-generated method stub
// Log.e(“”, “registration id : “+regId);
System.out.println("inside on registration");
handleRegistration(getApplicationContext(), regId);
}
#Override
protected void onUnregistered(Context context, String regId) {
// TODO Auto-generated method stub
}
private void handleRegistration(Context context, String regId) {
// TODO Auto-generated method stub
Log.e("", "registration id : "+regId);
}
}
and the below code:
public class Androidpushnotification extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, Constants.SenderId);
}
else {
Log.v("", "Already registered: "+regId);
}
}
#Override
protected void onDestroy() {
GCMRegistrar.onDestroy(this);
super.onDestroy();
}
}
manifest file:
<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.example.androidpushnotification.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.androidpushnotification.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.READ_PHONE_STATE" >
</uses-permission>
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Androidpushnotification"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.androidpushnotification" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
Could anybody help me regarding this ,Thanks
I think this problem is of Android OS version. I have faced same issue and found that Its only working with the OS version >= 4.1.
So, You might be testing it with Emulator version >= 4.1. and your device might be lower than os version 4.1.
Please check/test it with device with version 4.1 OR higher than that. You will find it working.
In-short, your code is right and its working code.
FYI: I think this issue occurs after 15th April,2013. and I have still not get any workaround for it.
If you/anyone find something in same direction then please share it with us.
Thanks,
- Umang Kathiyara
Related
I have setup my app for Parse notifications and strictly followed the instructions, but somehow I don't receive any notification. What is the problem here?
Update: I just tried sending a test push notification on the Parse.com website. That should work without subscribing to a channel (see comment)
My AndroidManifest.xml (only the relevant parts):
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:protectionLevel="signature"
android:name="co.bla.bla.permission.C2D_MESSAGE" />
<uses-permission android:name="co.bla.bla.permission.C2D_MESSAGE" />
<!-- Push notification setup -->
<service android:name="com.parse.PushService" />
<receiver android:name="co.bla.bla.ParsePushReceiver"
android:exported="false">
<intent-filter>
<action android:name="com.parse.push.intent.RECEIVE" />
<action android:name="com.parse.push.intent.DELETE" />
<action android:name="com.parse.push.intent.OPEN" />
</intent-filter>
</receiver>
<receiver android:name="com.parse.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="co.bla.bla" />
</intent-filter>
</receiver>
</application>
And I have extended ParsePushBroadcastReceiver:
public class ParsePushReceiver extends com.parse.ParsePushBroadcastReceiver{
#Override
protected void onPushReceive(Context context, Intent intent ) {
ParseAnalytics.trackAppOpenedInBackground(intent);
String s = intent.getStringExtra("alert");
Log.d("Push received", s);
// do your stuff here
if(SugarSnapApplication.INACTIVE)
super.onPushReceive(context, intent);
}
#Override
protected void onPushOpen(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, SugarActivity.class);
i.putExtras(intent.getExtras());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
#Override
protected Notification getNotification(Context context, Intent intent) {
// TODO Auto-generated method stub
return super.getNotification(context, intent);
}
#Override
protected void onPushDismiss(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onPushDismiss(context, intent);
}
}
I finally found out what the problem was. I have renamed the whole package name of my application a couple of days ago and apparently the change was not made everywhere and the applicationId in my build.gradle file was still the old one. So naturally the package name in my AndroidManifest.xml was not the same as the one saved in my Installation class.
In the log I am getting this message.
V/GCMBroadcastReceiver(30668): onReceive: com.google.android.c2dm.intent.REGISTRATION
08-07 11:12:59.096: V/GCMBroadcastReceiver(30668): GCM IntentService class: com.example.notifications.GCMIntentService
08-07 11:12:59.096: V/GCMBaseIntentService(30668): Acquiring wakelock
But OnRegistered method is not been invoked ( Running app in my MotoG device ). Below is the manifest.xml coding.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notifications"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="15" />
<permission android:name="com.example.notifications.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.notifications.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.notifications" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
And my MainActivitiy.java file
public static final String SENDER_ID = "xxxxxxxxx";
GCMRegistrar.checkDevice(MainActivity.this);
GCMRegistrar.checkManifest(MainActivity.this);
ChannelUri = GCMRegistrar.getRegistrationId(getApplicationContext());
if(ChannelUri.equals(""))
{
GCMRegistrar.register(getApplicationContext(), SENDER_ID);
}
else
{
Toast.makeText(getApplicationContext(), "Already Registered", Toast.LENGTH_SHORT).show();
}
GCMIntentService.java
public class GCMIntentService extends GCMBaseIntentService {
public static String sRegistrationId;
protected GCMIntentService() {
super(MainActivity.SENDER_ID);
}
public static String getRegistrationId()
{
return sRegistrationId;
}
#Override
protected void onError(Context arg0, String arg1) {
Log.e("Registration", "Got an error!");
Log.e("Registration", arg0.toString() + arg1.toString());
}
#Override
protected void onMessage(Context arg0, Intent intent) {
Log.i("Registration", "Got a message!");
Log.i("Registration", arg0.toString() + " " + intent.toString());
}
#Override
protected void onRegistered(Context arg0, String arg1) {
sRegistrationId = arg1;
Log.i("Registration", "Just registered!");
Log.i("Registration", arg0.toString() + arg1.toString());
}
#Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
}
Project Structure
Src -> com.example.notifications -> GCMIntentService.java, MainActivity.java
I followed the tutorial Android Push Notifications using Google Cloud Messaging (GCM), PHP and MySQL. My application only gets the notifications if I synchronize my mobile with Gmail before installing the application. If I install the application first and then synchronize my mobile with Gmail, it's not geting the notifcations.
Code
public class MainActivity extends Activity {
// Asynchronous task
AsyncTask<Void, Void, Void> mRegisterTask;
// Alert dialog manager
AlertDialogManager alert = new AlertDialogManager();
// Connection detector
ConnectionDetector cd;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cd = new ConnectionDetector(getApplicationContext());
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver,
new IntentFilter(DISPLAY_MESSAGE_ACTION));
// Get GCM registration id
final String regId = GCMRegistrar.getRegistrationId(this);
// Check if regid already presents
if (regId.equals("")) {
// Registration is not present, register now with GCM
GCMRegistrar.register(this, SENDER_ID);
}
else {
// The device is already registered on GCM
if (GCMRegistrar.isRegisteredOnServer(this)) {
// Skips registration.
Toast.makeText(getApplicationContext(), "Already registered with GCM",
Toast.LENGTH_LONG).show();
}
else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
final Context context = this;
mRegisterTask = new AsyncTask<Void, Void, Void>() {
#Override
protected Void doInBackground(Void... params) {
// Register on our server
// On server creates a new user
// ServerUtilities.register(context, name, email, regId);
ServerUtilities.register(context, regId);
return null;
}
#Override
protected void onPostExecute(Void result) {
mRegisterTask = null;
}
};
mRegisterTask.execute(null, null, null);
}
}
}
/**
* Receiving push messages
* */
private final BroadcastReceiver mHandleMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// newMessage = intent.getExtras().getString(EXTRA_MESSAGE);
// Waking up mobile if it is sleeping
WakeLocker.acquire(getApplicationContext());
/**
* Take appropriate action on this message
* depending upon your app requirement
* For now i am just displaying it on the screen
* */
// Releasing wake lock
WakeLocker.release();
}
};
#Override
protected void onDestroy() {
if (mRegisterTask != null) {
mRegisterTask.cancel(true);
}
try {
unregisterReceiver(mHandleMessageReceiver);
GCMRegistrar.onDestroy(this);
} catch (Exception e) {
Log.e("UnRegister Receiver Error", "> " + e.getMessage());
}
super.onDestroy();
}
}
Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.androidhive.pushnotifications"
android:versionCode="1"
android:versionName="1.0" >
<!-- GCM requires Android SDK version 2.2 (API level 8) or above. -->
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<!-- GCM connects to Internet Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Creates a custom permission so only this app can receive its messages. -->
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Network State Permissions to detect Internet status -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Permission to vibrate -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Main activity. -->
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<!-- Register Activity -->
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main Activity -->
<!-- <activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden"
android:label="#string/app_name" >
</activity>
-->
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- Receives the registration id. -->
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.androidhive.pushnotifications" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
</manifest>
LogCat error
10-01 02:35:12.809: V/GCMRegistrar(397): Unregistering receiver
10-01 02:35:12.809: E/UnRegister Receiver Error(397): > Receiver not registered:
com.google.android.gcm.GCMBroadcastReceiver#43e59e68
There must be at least one Google account registered on the device, else push notification does not work. You may refer to this document for more information. As it is mentioned,
For GCM to work, the mobile device must include at least one Google account if the device is running a version lower than Android 4.0.4.
EDIT : Also refer to this answer and make sure you have the same package name in your permission
<permission
android:name="com.androidhive.pushnotifications.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
and in the line below inside the intent-filter
<category android:name="com.androidhive.pushnotifications" />
I am not very experienced with Android development and I shall include gcm to an existing app.
So far, I can register all devices and I receive the registrationId. The problem is, that I never enter the onMessage() method on my Android 4.0 device. I also tried it with a Galaxy Note 2 (Android 4.1) and there I can receive the message.
I don't get any error message, I just never enter onMessage().
When I send the message, I always get an messageId, so gcm "accepted" the message. But it is never delivered to the device.
How can I find out what the problem is??? Thanks in advance
GCMIntentService.java
public class GCMIntentService extends GCMBaseIntentService {
public GCMIntentService() {
super("82........");
}
#Override
protected void onError(Context arg0, String error) {
System.out.println("Not able to register or unregister because: "
+ error);
}
#Override
protected void onMessage(Context context, Intent intent) {
String message = intent.getStringExtra("message");
System.out.println("GCM DELIVERED MESSAGE TO DEVICE:" + message);
}
#Override
protected void onRegistered(Context arg0, String regId) {
System.out.println("Device is registered with RegisterId: " + regId);
}
#Override
protected void onUnregistered(Context arg0, String regId) {
System.out.println("Device with RegisterId: " + regId
+ " has unregistered");
}
#Override
protected boolean onRecoverableError(Context context, String errorId) {
System.out.println("Entered onRecoverableError");
return super.onRecoverableError(context, errorId);
}
}
My Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.activities"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<permission
android:name="com.example.activities.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.activities.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Activity which is called first to decide which Activity comes next -->
<activity
android:name=".StartUp"
android:label="#string/title_activity_start_up" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="#string/title_activity_login" >
</activity>
<activity
android:name=".DisplayContent"
android:label="#string/title_activity_display_content" >
</activity>
<activity
android:name=".AllSigns"
android:label="#string/title_activity_all_signs" >
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.activities" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
Code in onCreate() of my first activity (Startup.java)
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
System.out.println("Id ist leer, Device wird neu registriert");
GCMRegistrar.register(this, "825134311331");
} else {
System.out.println("This device is already registered");
}
If you are trying this over WIFI, make sure that port 5228 isn't being blocked by the network. That's how I fixed the problem that I had after more days of trying to get it to work than I'd like to admit.
Make sure the GCMIntentService class is in the package specified in your manifest
I have a important delivery, i hope you can help me.
I have to use GCM.
I am using the file in the official guide in http://developer.android.com/guide/google/gcm/demo.html
I did "Setting Up the Server Using App Engine for Java" and it work.
My problem is the android application .Exactly I don't recive the id from GCM and so anytime my application try the registration.
Thanks a lot....
public class DemoActivity extends Activity {
TextView mDisplay;
AsyncTask<Void, Void, Void> mRegisterTask;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
checkNotNull(SERVER_URL, "SERVER_URL");
checkNotNull(SENDER_ID, "SENDER_ID");
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(this);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(this);
setContentView(R.layout.main);
mDisplay = (TextView) findViewById(R.id.display);
registerReceiver(mHandleMessageReceiver,
new IntentFilter(DISPLAY_MESSAGE_ACTION));
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, SENDER_ID);
} else {
....
}
CommonUtilities
public final class CommonUtilities
{
static final String SERVER_URL = "http://127.0.0.1:8888/gcmdemo4/home";
static final String SENDER_ID = "843761346XXX";
...
}
GCMIntentService
public class GCMIntentService extends GCMBaseIntentService {
#SuppressWarnings("hiding")
private static final String TAG = "GCMIntentService";
public GCMIntentService() {
super(SENDER_ID);
}
#Override
public void onRegistered(Context context, String registrationId) {
Log.i(TAG, "Device registered: regId = " + registrationId);
displayMessage(context, getString(R.string.gcm_registered));
ServerUtilities.register(context, registrationId);
}
.....
MY manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.registrazionegcm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<permission
android:name="com.example.registrazionegcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.registrazionegcm.permission.C2D_MESSAGE" />
<!-- App receives GCM messages. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- GCM connects to Google Services. -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- GCM requires a Google account. -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="DemoActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="com.google.android.gcm.GCMBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.example.registrazionegcm" />
</intent-filter>
</receiver>
<service android:name=".GCMIntentService" />
</application>
could you supply your code of "registerReceiver".
I had the same problem, when my SENDER_ID was wrong.
Try to check it again, and check your package too: com.example.registrazionegcm.GCMIntentService
Put some breakpoint in onError and onRegistered
For me, this code works:
#Override
public void run() {
GCMRegistrar.checkDevice(mContext);
GCMRegistrar.checkManifest(mContext);
String deviceToken = GCMRegistrar.getRegistrationId(mContext);
if (deviceToken.equals("")) {
GCMRegistrar.register(mContext, "XXXXXXXXXXXXXXX");
deviceToken = GCMRegistrar.getRegistrationId(mContext);
if(!deviceToken.equals("")){
GCMRegistrar.setRegisteredOnServer(mContext, true);
// register deviceToken on CommNotes srv
RequestMaker req = new RequestMaker(Constant.REQ_REGISTER_GCM, mContext);
//if unsuccessful, try again 5 times
for(int i = 0; i<5; i++){
Log.d("ComNotes", "registration id"+deviceToken);
if(req.doRequest(deviceToken) == ReturnCode.CODE_OK){
break;
}
}
}
//TODO manage unsuccess: display error : "No PUSH available"
} else {
Log.v("CommunityNotes", "Already registered "+deviceToken);
}
}