Java Code Examples for com.google.android.gcm.GCMRegistrar#checkDevice()
The following examples show how to use
com.google.android.gcm.GCMRegistrar#checkDevice() .
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 |
/** * 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 |
/** * 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: PushMainActivity.java From apigee-android-sdk with Apache License 2.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // this is a hack to force AsyncTask to be initialized on main thread. Without this things // won't work correctly on older versions of Android (2.2, apilevel=8) try { Class.forName("android.os.AsyncTask"); } catch (Exception ignored) {} GCMRegistrar.checkDevice(this); GCMRegistrar.checkManifest(this); initUI(); AppServices.loginAndRegisterForPush(this); }
Example 4
Source File: AndroidMessageReceiverService.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 5
Source File: MultiplexingGcmListener.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: KlyphGCM.java From Klyph with MIT License | 5 votes |
public static void registerIfNecessary() { final Context context = KlyphApplication.getInstance(); try { GCMRegistrar.checkDevice(context); } catch (UnsupportedOperationException e) { return; } // GCMRegistrar.checkManifest(context); final String regId = KlyphPreferences.getGCMRegId(); // Register GCM if (regId.length() == 0) { Log.d("KlyphGCM", "register GCM"); registerTask = new RegisterTask(); registerTask.execute(context); } else { // Register on server, maybe last attempt failed Log.d("KlyphGCM", "register on server"); registerOnServerTask = new RegisterOnServerTask(); registerOnServerTask.execute(context); } }
Example 7
Source File: PushManager.java From divide with Apache License 2.0 | 5 votes |
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 8
Source File: Global.java From Favorite-Android-Client with Apache License 2.0 | 5 votes |
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 9
Source File: AndroidMessageReceiverService.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 10
Source File: MultiplexingGcmListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 11
Source File: AndroidMessageReceiverService.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 12
Source File: MultiplexingGcmListener.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * 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 13
Source File: GCMIntentService.java From solutions-mobile-shopping-assistant-android-client with Apache License 2.0 | 4 votes |
/** * 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 14
Source File: MagpiMainActivity.java From magpi-android with MIT License | 4 votes |
@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 15
Source File: GCMIntentService.java From solutions-mobile-shopping-assistant-backend-java with Apache License 2.0 | 2 votes |
/** * 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); }