Java Code Examples for com.google.android.gcm.GCMRegistrar#register()

The following examples show how to use com.google.android.gcm.GCMRegistrar#register() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From datmusic-android with Apache License 2.0 6 votes vote down vote up
/**
 * Registers GCM and sends to server
 */
private void registerGCM() {
    try {
        GCMRegistrar.checkDevice(this);
        GCMRegistrar.checkManifest(this);
        final String regId = GCMRegistrar.getRegistrationId(this);
        if (regId.equals("")) {
            GCMRegistrar.register(this, Config.GCM_SENDER_ID);
        } else {
            if (Remember.getBoolean("gcmSent", false)) {
                ApiService.getClientJackson().register(
                    regId,
                    U.getDeviceId(this)
                ).enqueue(new Summon<Result>() {
                    @Override
                    public void onSuccess(Call<Result> call, Response<Result> response) {
                        Remember.putBoolean("gcmSent", true);
                    }
                });
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: Util.java    From ownmdm with GNU General Public License v2.0 6 votes vote down vote up
/**
   * GCM
   */
  public static void setGCM(Context context) {
      //
      // GCM
      //
try {
       GCMRegistrar.checkDevice(context);
       GCMRegistrar.checkManifest(context);
       final String regId = GCMRegistrar.getRegistrationId(context);
       
       if (regId.equals("")) {
       	GCMRegistrar.register(context, Util.SENDER_ID);
       } else {
       	Util.regId = regId;
       	Util.logDebug("Already registered - imei: " + Util.imei + " gcm: " + regId);

       	Util.registradoGCM = true; // marcar como registrado para no intentarlo m�s

       	registerOnLocalServer(context); // lo hago otra vez para asegurar
       }
      
} catch (Exception e) {
	Util.logDebug("Exception setGCM: " + e.getMessage());
}
  	
  }
 
Example 3
Source File: CaffeinaGCMModule.java    From gcm with MIT License 5 votes vote down vote up
@Kroll.method
@SuppressWarnings("unchecked")
public void registerForPushNotifications(HashMap options) {
	String senderId = (String)options.get("senderId");

	successCallback = (KrollFunction)options.get("success");
	errorCallback = (KrollFunction)options.get("error");
	messageCallback = (KrollFunction)options.get("callback");

	if (senderId != null) {
		GCMRegistrar.register(TiApplication.getInstance(), senderId);
	} else {
		sendError("No GCM senderId specified; get it from the Google Play Developer Console");
	}
}
 
Example 4
Source File: MultiplexingGcmListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Registers with GCM if not already registered. Also verifies that the device supports GCM
 * and that the manifest is correctly configured. Returns the existing registration id, if one
 * exists, or the empty string if one does not.
 *
 * @throws UnsupportedOperationException if the device does not have all GCM dependencies
 * @throws IllegalStateException if the manifest is not correctly configured
 */
public static String initializeGcm(Context context) {
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  final String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    GCMRegistrar.register(context, readSenderIdsFromManifestOrDie(context));
  }
  return regId;
}
 
Example 5
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Initializes GCM as a convenience method for tests. In production, applications should handle
 * this.
 */
public static void initializeGcmForTest(Context context, Logger logger, String senderId) {
  // Initialize GCM.
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    logger.info("Not registered with GCM; registering");
    GCMRegistrar.register(context, senderId);
  } else {
    logger.fine("Already registered with GCM: %s", regId);
  }
}
 
Example 6
Source File: MultiplexingGcmListener.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Registers with GCM if not already registered. Also verifies that the device supports GCM
 * and that the manifest is correctly configured. Returns the existing registration id, if one
 * exists, or the empty string if one does not.
 *
 * @throws UnsupportedOperationException if the device does not have all GCM dependencies
 * @throws IllegalStateException if the manifest is not correctly configured
 */
public static String initializeGcm(Context context) {
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  final String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    GCMRegistrar.register(context, readSenderIdsFromManifestOrDie(context));
  }
  return regId;
}
 
Example 7
Source File: AndroidMessageReceiverService.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Initializes GCM as a convenience method for tests. In production, applications should handle
 * this.
 */
public static void initializeGcmForTest(Context context, Logger logger, String senderId) {
  // Initialize GCM.
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.equals("")) {
    logger.info("Not registered with GCM; registering");
    GCMRegistrar.register(context, senderId);
  } else {
    logger.fine("Already registered with GCM: %s", regId);
  }
}
 
Example 8
Source File: Client.java    From apigee-android-sdk with Apache License 2.0 5 votes vote down vote up
public void registerPush(Context context) {
    final String regId = GCMRegistrar.getRegistrationId(context);
    if ("".equals(regId)) {
        GCMRegistrar.register(context, GCM_SENDER_ID);
    } else {
        if (GCMRegistrar.isRegisteredOnServer(context)) {
            Log.i(TAG, "Already registered with GCM");
        } else {
            this.registerPush(context, regId);
        }
    }
}
 
Example 9
Source File: AppServices.java    From apigee-android-sdk with Apache License 2.0 5 votes vote down vote up
static void registerPush(Context context) {

    final String regId = GCMRegistrar.getRegistrationId(context);

    if ("".equals(regId)) {
      GCMRegistrar.register(context, Settings.GCM_SENDER_ID);
    } else {
      if (GCMRegistrar.isRegisteredOnServer(context)) {
        Log.i(TAG, "Already registered with GCM");
      } else {
        AppServices.register(context, regId);
      }
    }
  }
 
Example 10
Source File: Global.java    From Favorite-Android-Client with Apache License 2.0 5 votes vote down vote up
public static String GCMReg() {
	GCMRegistrar.checkDevice(mod);
	GCMRegistrar.checkManifest(mod);
	final String regId = GCMRegistrar.getRegistrationId(ModApplication
			.getInstance());
	if ("".equals(regId)) // 구글 가이드에는 regId.equals("")로 되어 있는데
							// Exception을 피하기 위해 수정
		GCMRegistrar.register(mod, "743824910564");

	return regId;

}
 
Example 11
Source File: PushManager.java    From divide with Apache License 2.0 5 votes vote down vote up
private void register4Push(){
    Context context = config.app;
    GCMRegistrar.checkDevice(context);
    GCMRegistrar.checkManifest(context);
    final String regId = GCMRegistrar.getRegistrationId(context);
    if (regId.equals("")) {
        logger.info("Registering");
        GCMRegistrar.setRegisteredOnServer(context, true);
        GCMRegistrar.register(context, senderId);
    } else {
        logger.info("Push already registered: " + regId);
    }
}
 
Example 12
Source File: GCMModule.java    From gcmpush with Apache License 2.0 5 votes vote down vote up
@Kroll.method
@SuppressWarnings("unchecked")
public void registerPush(HashMap options) {

    Log.d(LCAT, "registerPush called");

    String senderId = (String) options.get("senderId");
    Map<String, Object> notificationSettings = (Map<String, Object>) options.get("notificationSettings");
    successCallback = (KrollFunction) options.get("success");
    errorCallback = (KrollFunction) options.get("error");
    messageCallback = (KrollFunction) options.get("callback");

    /* Store notification settings in global Ti.App properties */
    JSONObject json = new JSONObject(notificationSettings);
    TiApplication.getInstance().getAppProperties().setString(GCMModule.NOTIFICATION_SETTINGS, json.toString());

    if (senderId != null) {
        GCMRegistrar.register(TiApplication.getInstance(), senderId);

        String registrationId = getRegistrationId();
        if (registrationId != null && registrationId.length() > 0) {
            sendSuccess(registrationId);
        }
    } else {
        sendError(errorCallback, "No GCM senderId specified; get it from the Google Play Developer Console");
    }
}
 
Example 13
Source File: MultiplexingGcmListener.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Registers with GCM if not already registered. Also verifies that the device supports GCM
 * and that the manifest is correctly configured. Returns the existing registration id, if one
 * exists, or the empty string if one does not.
 *
 * @throws UnsupportedOperationException if the device does not have all GCM dependencies
 * @throws IllegalStateException if the manifest is not correctly configured
 */
public static String initializeGcm(Context context) {
  AndroidChannelPreferences.setGcmChannelType(context, GcmChannelType.DEFAULT);
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  final String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.isEmpty()) {
    GCMRegistrar.register(context, readSenderIdsFromManifestOrDie(context));
  }
  return regId;
}
 
Example 14
Source File: AndroidMessageReceiverService.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes GCM as a convenience method for tests. In production, applications should handle
 * this.
 */
public static void initializeGcmForTest(Context context, Logger logger, String senderId) {
  // Initialize GCM.
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  String regId = GCMRegistrar.getRegistrationId(context);
  if (regId.isEmpty()) {
    logger.info("Not registered with GCM; registering");
    GCMRegistrar.register(context, senderId);
  } else {
    logger.fine("Already registered with GCM: %s", regId);
  }
}
 
Example 15
Source File: GCMIntentService.java    From solutions-mobile-shopping-assistant-android-client with Apache License 2.0 4 votes vote down vote up
/**
 * Register the device for GCM.
 *
 * @param context the activity's context.
 */
public static void register(Context context) {
  GCMRegistrar.checkDevice(context);
  GCMRegistrar.checkManifest(context);
  GCMRegistrar.register(context, GCM_PROJECT_ID);
}
 
Example 16
Source File: MagpiMainActivity.java    From magpi-android with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_magpi_main);
    
    try {
     GCMRegistrar.checkDevice(this);
     GCMRegistrar.checkManifest(this);
     final String idGcm = GCMRegistrar.getRegistrationId(this);
     if (TextUtils.isEmpty(idGcm)) {
     	Log.e("GCM", "NOT registered");
         GCMRegistrar.register(MagpiMainActivity.this, Config.SENDER_ID);
     } else {
     	Log.e("GCM", "Already registered" + idGcm);
     	if(isTimeToRegister())
     		new MagPiClient().registerDevice(this, idGcm);
     }
    } catch (UnsupportedOperationException ex) {
    	Log.e("GCM", "Google Cloud Messaging not supported - please install Google Apps package!");
    }

    mOnNavigationListener = new OnNavigationListener() {
        @Override
        public boolean onNavigationItemSelected(int position, long itemId) {
            return true;
        }
    };
    
    this.intialiseViewPager();
 
    CompatActionBarNavHandler handler = new CompatActionBarNavHandler(this);
    
    SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.dropdown_array,
            android.R.layout.simple_spinner_dropdown_item);
    
    getSupportActionBar().setListNavigationCallbacks(mSpinnerAdapter, mOnNavigationListener);
    getSupportActionBar().setNavigationMode(android.app.ActionBar.NAVIGATION_MODE_TABS);
    
    final String CATEGORIES[] = getResources().getStringArray(R.array.dropdown_array);
    for (int i = 0; i < CATEGORIES.length; i++) {
        this.getSupportActionBar().addTab(this.getSupportActionBar().newTab().setText(
            CATEGORIES[i]).setTabListener(handler));
    }
    getSupportActionBar().setSelectedNavigationItem(0);
    
}
 
Example 17
Source File: KlyphGCM.java    From Klyph with MIT License 4 votes vote down vote up
@Override
protected Void doInBackground(Context... params)
{
	GCMRegistrar.register(params[0], CommonUtilities.SENDER_ID);
	return null;
}
 
Example 18
Source File: GCMIntentService.java    From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 2 votes vote down vote up
/**
 * Register the device for GCM.
 * 
 * @param mContext
 *            the activity's context.
 */
public static void register(Context mContext) {
  GCMRegistrar.checkDevice(mContext);
  GCMRegistrar.checkManifest(mContext);
  GCMRegistrar.register(mContext, PROJECT_NUMBER);
}