当前位置: 首页>>代码示例>>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;未经允许,请勿转载。