Back to project page droidBBpush.
The source code is released under:
This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a co...
If you think the Android project droidBBpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.arg3.examples.droidbb.gcm; //from www . j av a 2s . c om import android.app.Activity; import android.content.Context; import android.util.Log; import com.arg3.examples.droidbb.PushRegistrar; import com.arg3.examples.droidbb.PushService; import com.google.android.gcm.GCMRegistrar; import javax.inject.Inject; /** * Created by ryan on 2014-08-13. */ public class GCMHandler implements PushService { private static final String TAG = GCMHandler.class.getName(); boolean available; PushRegistrar registrar; @Inject GCMHandler(PushRegistrar registrar) { this.registrar = registrar; } @Override public void init(Activity context) { final String regId = GCMRegistrar.getRegistrationId(context); if (regId.equals("")) { try { Log.i(TAG, "Initializing push messaging"); /* some sanity checking, might want to handle exceptions better */ GCMRegistrar.checkDevice(context); GCMRegistrar.checkManifest(context); GCMRegistrar.register(context, SENDER_ID); available = true; } catch (UnsupportedOperationException e) { Log.e(TAG, e.getMessage()); Log.e(TAG, "Push messaging not available."); available = false; } } else { registrar.storeRegistrationId(regId); } } public boolean isAvailable() { return available; } @Override public void destroy(Context context) { GCMRegistrar.onDestroy(context); } }