android - i am not getting the device Registration id from the google and even not called GCMIntentService -
i not getting device registration id google , not called gcmintentservice
using google create server key..
below manifest file not getting device register key google
package="com.example.isquare.pushexample" > <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.isquare.pushexample" /> </intent-filter> </receiver> <service android:name=".myintentservice" /> </application> <uses-permission android:name="android.permission.internet" /> <!-- gcm requires google account. --> <permission android:name="com.example.isquare.pushexample.permission.c2d_message" android:protectionlevel="signature" /> <uses-permission android:name="com.example.isquare.pushexample.permission.c2d_message" /> <!-- app has permission register , receive data message. --> <uses-permission android:name="com.google.android.c2dm.permission.receive" /> <!-- network state permissions detect internet status --> <uses-permission android:name="android.permission.access_network_state" /> <!-- permission vibrate --> <uses-permission android:name="android.permission.vibrate" />
here gcmintentservice
public class gcmintentservice extends gcmbaseintentservice { private static final string tag = "gcmintentservice"; private controller acontroller = null; public gcmintentservice() { // call extended class constructor gcmbaseintentservice super(config.google_sender_id); system.out.println("the gcm id "); } @override protected void onmessage(context context, intent intent) { if(acontroller == null) acontroller = (controller) getapplicationcontext(); log.i(tag, "received message"); string message = intent.getextras().getstring("price"); acontroller.displaymessageonscreen(context, message); // notifies user generatenotification(context, message); } @override protected void onerror(context context, string errorid) { if(acontroller == null) acontroller = (controller) getapplicationcontext(); log.i(tag, "received error: " + errorid); acontroller.displaymessageonscreen(context, getstring(r.string.gcm_error, errorid)); } @override protected void ondeletedmessages(context context, int total) { if(acontroller == null) acontroller = (controller) getapplicationcontext(); log.i(tag, "received deleted messages notification"); string message = getstring(r.string.gcm_deleted, total); acontroller.displaymessageonscreen(context, message); // notifies user generatenotification(context, message); } @override protected boolean onrecoverableerror(context context, string errorid) { return super.onrecoverableerror(context, errorid); } @override protected void onregistered(context context, string registrationid) { //get global controller class object (see application tag in androidmanifest.xml) if(acontroller == null) acontroller = (controller) getapplicationcontext(); log.i(tag, "device registered: regid = " + registrationid); acontroller.displaymessageonscreen(context, "your device registred gcm"); log.d("name", mainactivity.name); acontroller.register(context, mainactivity.name, mainactivity.email, registrationid); } @override protected void onunregistered(context context, string registrationid) { if(acontroller == null) acontroller = (controller) getapplicationcontext(); log.i(tag, "device unregistered"); acontroller.displaymessageonscreen(context, getstring(r.string.gcm_unregistered)); acontroller.unregister(context, registrationid); } private static void generatenotification(context context, string message) { int icon = r.drawable.ic_launcher; long when = system.currenttimemillis(); notificationmanager notificationmanager = (notificationmanager) context.getsystemservice(context.notification_service); notification notification = new notification(icon, message, when); string title = context.getstring(r.string.app_name); intent notificationintent = new intent(context, mainactivity.class); // set intent not start new activity notificationintent.setflags(intent.flag_activity_clear_top | intent.flag_activity_single_top); pendingintent intent = pendingintent.getactivity(context, 0, notificationintent, 0); notification.setlatesteventinfo(context, title, message, intent); notification.flags |= notification.flag_auto_cancel; // play default notification sound notification.defaults |= notification.default_sound; //notification.sound = uri.parse( "android.resource://" + context.getpackagename() + "your_sound_file_name.mp3"); // vibrate if vibrate enabled notification.defaults |= notification.default_vibrate; notificationmanager.notify(0, notification); }
broadcast receiver:
private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string newmessage = intent.getextras().getstring(config.extra_message); acontroller.acquirewakelock(getapplicationcontext()); system.out.println(newmessage + ""); toast.maketext(getapplicationcontext(), "got message: " + newmessage, toast.length_long).show(); acontroller.releasewakelock(); } };
private final broadcastreceiver mhandlemessagereceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { string newmessage = intent.getextras().getstring(config.extra_message); acontroller.acquirewakelock(getapplicationcontext()); system.out.println(newmessage + ""); toast.maketext(getapplicationcontext(), "got message: " + newmessage, toast.length_long).show(); acontroller.releasewakelock(); }
};
Comments
Post a Comment