android - Replacing GCMBaseIntentService with GoogleCloudMessaging -


i new android development , had switch first project eclipse android studio finding library gcmbaseintentservice no longer supported. found googlecloudmessaging, not @ evident how port implementation got tutorial http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/ here listed, that. may help?

this piece of code need replace:

package com.example.taxiprofessional;  import android.app.notification; import android.app.notificationmanager; import android.app.pendingintent; import android.content.context; import android.content.intent; import android.util.log;  import com.google.android.gcm.gcmbaseintentservice;  import static com.example.taxiprofessional.commonutilities.sender_id; import static com.example.taxiprofessional.commonutilities.displaymessage;  public class gcmintentservice extends gcmbaseintentservice {      private static final string tag = "gcmintentservice";   public gcmintentservice() {      super(sender_id);  }   /**   * method called on device registered   **/  @override  protected void onregistered(context context, string registrationid) {      log.i(tag, "device registered: regid = " + registrationid);      displaymessage(context, "your device registred gcm");      accountinformation info=accountinformation.sharedinstance();      serverutilities.register(context, info.email, info.password, registrationid);  }   /**   * method called on device un registred   * */  @override  protected void onunregistered(context context, string registrationid) {      log.i(tag, "device unregistered");      displaymessage(context, getstring(r.string.gcm_unregistered));      serverutilities.unregister(context, registrationid);  }   /**   * method called on receiving new message   * */  @override  protected void onmessage(context context, intent intent) {      log.i(tag, "received message");      string message = intent.getextras().getstring("price");       displaymessage(context, message);      // notifies user      generatenotification(context, message);  }   /**   * method called on receiving deleted message   * */  @override  protected void ondeletedmessages(context context, int total) {      log.i(tag, "received deleted messages notification");      string message = getstring(r.string.gcm_deleted, total);      displaymessage(context, message);      // notifies user      generatenotification(context, message);  }   /**   * method called on error   * */  @override  public void onerror(context context, string errorid) {      log.i(tag, "received error: " + errorid);      displaymessage(context, getstring(r.string.gcm_error, errorid));  }   @override  protected boolean onrecoverableerror(context context, string errorid) {      // log message      log.i(tag, "received recoverable error: " + errorid);      displaymessage(context, getstring(r.string.gcm_recoverable_error,              errorid));      return super.onrecoverableerror(context, errorid);  }   /**   * issues notification inform user server has sent message.   */  private static void generatenotification(context context, string message) {      int icon = r.drawable.taxi_profi;      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, dashboard.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;       // vibrate if vibrate enabled      notification.defaults |= notification.default_vibrate;      notificationmanager.notify(0, notification);         }  } 

thanks, fabrizio


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -