當前位置: 首頁>>代碼示例>>Java>>正文


Java GCMRegistrar.getRegistrationId方法代碼示例

本文整理匯總了Java中com.google.android.gcm.GCMRegistrar.getRegistrationId方法的典型用法代碼示例。如果您正苦於以下問題:Java GCMRegistrar.getRegistrationId方法的具體用法?Java GCMRegistrar.getRegistrationId怎麽用?Java GCMRegistrar.getRegistrationId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gcm.GCMRegistrar的用法示例。


在下文中一共展示了GCMRegistrar.getRegistrationId方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getRegistrationId

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
public static String getRegistrationId(Context paramContext)
{
  int i = Build.VERSION.SDK_INT;
  if (i < 8) {
    throw new UnsupportedOperationException("Device must be at least API Level 8 (instead of " + i + ")");
  }
  PackageManager localPackageManager = paramContext.getPackageManager();
  try
  {
    localPackageManager.getPackageInfo("com.google.android.gsf", 0);
    String str = GCMRegistrar.getRegistrationId(paramContext);
    if (TextUtils.isEmpty(str))
    {
      FinskyLog.d("Start requesting GCM Reg Id", new Object[0]);
      String[] arrayOfString = { "932144863878" };
      GCMRegistrar.resetBackoff(paramContext);
      GCMRegistrar.internalRegister(paramContext, arrayOfString);
      str = null;
    }
    return str;
  }
  catch (PackageManager.NameNotFoundException localNameNotFoundException)
  {
    throw new UnsupportedOperationException("Device does not have package com.google.android.gsf");
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:27,代碼來源:GcmRegistrationIdHelper.java

示例2: onCreate

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_splash);
	// Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(
	// SplashActivity.this));
	mApplication = (InternalApp) getApplication();
	if (!mApplication.isTabletLayout()) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
	}
	GCMRegistrar.checkDevice(this);
	GCMRegistrar.checkManifest(this);

	final String regId = GCMRegistrar.getRegistrationId(this);
	if (regId.equals("")) {
		// Automatically registers application on startup.
		GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
	}

	initiateSkillsApi();
	hideActionbar();
	getAllReferences();
	loadControls();
	loadAnimation();
}
 
開發者ID:himanshuagarwal77225,項目名稱:BookMySkills,代碼行數:26,代碼來源:SplashActivity.java

示例3: registerGCM

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
 * 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();
    }
}
 
開發者ID:alashow,項目名稱:datmusic-android,代碼行數:28,代碼來源:MainActivity.java

示例4: getPushNotificationSettings

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
public static void getPushNotificationSettings(Context context, RestRequest.Listener listener,
                                               RestRequest.ErrorListener errorListener) {
    if (!WordPress.hasDotComToken(context)) {
        return;
    }

    String gcmToken = GCMRegistrar.getRegistrationId(context);
    if (TextUtils.isEmpty(gcmToken)) {
        return;
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    String deviceID = settings.getString(WPCOM_PUSH_DEVICE_SERVER_ID, null);
    if (TextUtils.isEmpty(deviceID)) {
        AppLog.e(T.NOTIFS, "device_ID is null in preferences. Get device settings skipped.");
        return;
    }

    WordPress.getRestClientUtils().get("/device/" + deviceID, listener, errorListener);
}
 
開發者ID:ldsddn,項目名稱:wordpress_app_android,代碼行數:21,代碼來源:NotificationsUtils.java

示例5: Register

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
static void Register(Context context, Boolean force) {
	taskWasForced = force;
	originalContext = context;
	
	if (force || !IsRegistered(context)) {
		String regId = GCMRegistrar.getRegistrationId(context);
		if (!force && regId != "") {
			RegisterOnDeveloperServer(context, regId);
		} else {
			GCMRegistrar.setRegisteredOnServer(context, false);
			try {
				GCMRegistrar.register(context, APP_GCM_ID);
			} catch (Exception ex) {
				OnRegistrationFail(context);
			}
		}
	}
}
 
開發者ID:deepankarb,項目名稱:android-Notifier,代碼行數:19,代碼來源:Registration.java

示例6: setGCM

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
   * 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());
}
  	
  }
 
開發者ID:pacosal,項目名稱:ownmdm,代碼行數:29,代碼來源:Util.java

示例7: getRegistrationId

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
 * Returns registration id associated with the specified {@link Application}.
 * This method will block the thread until regId will be available.
 *
 * @param app
 *          {@link Application}
 * @return registration id
 */
public static String getRegistrationId(Application app) {

  // try to get regId
  String regId = GCMRegistrar.getRegistrationId(app);
  if (regId != null && regId.trim().length() > 0) {
    return regId;
  }

  // wait for regId from onRegistered
  try {
    latch.await();
  } catch (InterruptedException e) {
    if (Consts.DEBUG) {
      Log.i(Consts.TAG, "getRegistrationId: ", e);
    }
  }
  regId = GCMRegistrar.getRegistrationId(app);
  if (regId != null && regId.trim().length() > 0) {
    return regId;
  } else {
    throw new IllegalStateException("getRegistrationId: Can't find regId for: " + app);
  }
}
 
開發者ID:EnteriseToolkit,項目名稱:codetalk,代碼行數:32,代碼來源:GCMIntentService.java

示例8: run

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
public void run()
{
    Context applicationContext = getApplicationContext();
    GCMRegistrar.checkDevice(applicationContext);
    GCMRegistrar.checkManifest(applicationContext);
    final String regId = GCMRegistrar.getRegistrationId(applicationContext);
    if (regId.equals(""))
    {
	GCMRegistrar.register(applicationContext, GCM_PROJECT_ID);
    }
    else
    {
	Log.v("regId", regId);
    }
}
 
開發者ID:spotstationaut,項目名稱:spotthestation,代碼行數:17,代碼來源:MapActivity.java

示例9: getRegistrationId

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
 * Returns registration id associated with the specified {@link Application}.
 * This method will block the thread until regId will be available.
 *
 * @param app
 *          {@link Application}
 * @return registration id
 */
public static String getRegistrationId(Application app) {

  // try to get regId
  String regId = GCMRegistrar.getRegistrationId(app);
  if (regId != null && regId.trim().length() > 0) {
    return regId;
  }

  // wait for regId from onRegistered
  try {
    latch.await();
  } catch (InterruptedException e) {
    Log.i(Consts.TAG, "getRegistrationId: ", e);
  }
  regId = GCMRegistrar.getRegistrationId(app);
  if (regId != null && regId.trim().length() > 0) {
    return regId;
  } else {
    throw new IllegalStateException("getRegistrationId: Can't find regId for: " + app);
  }
}
 
開發者ID:harrypritchett,項目名稱:Give-Me-Ltc-Android-App,代碼行數:30,代碼來源:GCMIntentService.java

示例10: initializeGCM

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
/**
 * Initializes Google Cloud Messaging
 */
private void initializeGCM() {

  try {

    Context context = activity.getApplicationContext();

    GCMRegistrar.checkDevice(context);
    GCMRegistrar.checkManifest(context);

    String regId = GCMRegistrar.getRegistrationId(context);

    if (regId == null || regId.trim().length() == 0 || !GCMRegistrar.isRegistered(context)
        || !GCMRegistrar.isRegisteredOnServer(context)) {
      GCMRegistrar.register(context, GameBackendSettings.GCM_SENDER_ID);
    }
  } catch (RuntimeException e) {
    Log.e(TAG, "initializeGCM", e);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:solutions-griddler-sample-android-client,代碼行數:23,代碼來源:GoogleServicesFragment.java

示例11: getVertretungsplan

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
public Vertretungsplan getVertretungsplan() throws IOException,
		JSONException, VersionException, UnauthorizedException {
	String regId = GCMRegistrar.getRegistrationId(VertretungsplanApplication.context);
	Log.d("vertretungsplan", schoolId);
	String url = BASE_URL + "vertretungsplan?school=" + schoolId + "&regId=" + URLEncoder.encode(regId, "UTF-8") + "&" + VERSION;
	Log.d("vertretungsplan", url);
	Response response = new Request(url).getResource("UTF-8");
	if(response.getResponseCode() == 400)
		throw new VersionException();
	else if (response.getResponseCode() == 401)
		throw new UnauthorizedException();
	else if (response.getResponseCode() == 200) {
		Vertretungsplan v = new Gson().fromJson(response.getBody(), Vertretungsplan.class);
		return v;
	} else {
		throw new IOException("response: " + response.getResponseCode());
	}
}
 
開發者ID:johan12345,項目名稱:ls-vertretungsplan,代碼行數:20,代碼來源:BackendConnectParser.java

示例12: gcmRegistration

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
private void gcmRegistration() {
	String senderId = Preferences.getSenderId(this);

    try {
		GCMRegistrar.checkDevice(this);
	    GCMRegistrar.checkManifest(this);
		final String registrationId = GCMRegistrar.getRegistrationId(this);
		if( registrationId != null && !"".equals(registrationId) ) {
			Log.d(TAG, "Already registered. registrationId is " + registrationId);
		} else {
			Log.d(TAG, "No existing registrationId. Registering.");
			GCMRegistrar.register(this, senderId);
		}
    } catch (UnsupportedOperationException e) {
        Toast.makeText(this, R.string.gcm_not_supported, Toast.LENGTH_SHORT).show();
    }
	
}
 
開發者ID:thunderace,項目名稱:newtifry,代碼行數:19,代碼來源:Newtifry.java

示例13: onCreate

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

		GCMRegistrar.checkDevice(this);
		GCMRegistrar.checkManifest(this);

		    final String regId = GCMRegistrar.getRegistrationId(this);

		    if (regId.equals("")) {				// if regId not present get one.
		        GCMRegistrar.register(this, "SENDER_ID");
		    } else {						//regID already present just send a request to server to get back a notification.
				HttpRequest request = new HttpRequest("POST");	//GET OR POST 
				request.setAction("GcmTesting");
				request.setContext(getApplicationContext());
				request.setGCMID(regId);
				request.LoadResources();		//never forget to call this after params are set.
				request.ExecuteRequest();		//this function returns a string which you echoed on the server.
												//You can catch it if you want.
		    }
		    

}
 
開發者ID:mozi22,項目名稱:GCM-Notification-Example,代碼行數:25,代碼來源:MainActivity.java

示例14: onCreate

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	new AsyncTask<Void, Void, Void>() {
	      @Override
	      protected Void doInBackground(Void... params) {
	        return null;
	      }
	    }.execute();
	setContentView(R.layout.activity_main);
	GCMRegistrar.checkDevice(this);
	GCMRegistrar.checkManifest(this);
	final String regId = GCMRegistrar.getRegistrationId(this);
	
	  GCMRegistrar.register(this, "272275396485");
	
}
 
開發者ID:secondsun,項目名稱:devnexus2013demo,代碼行數:18,代碼來源:MainActivity.java

示例15: registerAtGCM

import com.google.android.gcm.GCMRegistrar; //導入方法依賴的package包/類
protected static void registerAtGCM(Context context) {
    GCMRegistrar.checkDevice(context);
    GCMRegistrar.checkManifest(context);
    
    final String regId = GCMRegistrar.getRegistrationId(context);
    if (regId.equals("")) {
        GCMRegistrar.register(context, SENDER_ID);
        Log.v(TAG, "Already registered:sdnmbg " + regId);
    } else {
        Log.v(TAG, "Already registered: " + regId);
    }
   
}
 
開發者ID:muneerulhudha,項目名稱:ThereWillBeBlood,代碼行數:14,代碼來源:GCMIntentService.java


注:本文中的com.google.android.gcm.GCMRegistrar.getRegistrationId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。