本文整理汇总了Java中com.google.samples.apps.iosched.gcm.ServerUtilities类的典型用法代码示例。如果您正苦于以下问题:Java ServerUtilities类的具体用法?Java ServerUtilities怎么用?Java ServerUtilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServerUtilities类属于com.google.samples.apps.iosched.gcm包,在下文中一共展示了ServerUtilities类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: registerGCMClient
import com.google.samples.apps.iosched.gcm.ServerUtilities; //导入依赖的package包/类
/**
* Registers device on the GCM server, if necessary.
* <p/>
* This check is done in BaseActivity (as opposed to {@link AppApplication}) in order to make sure
* that this is always run after a user switch.
* <p/>
* As a future improvement, this code could be manually invoked by the app after a user
* switch occurs, which would allow moving this code to {@link AppApplication}.
*/
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, BuildConfig.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:65,代码来源:BaseActivity.java
示例2: registerGCMClient
import com.google.samples.apps.iosched.gcm.ServerUtilities; //导入依赖的package包/类
/** Registers device on the GCM server, if necessary. */
private void registerGCMClient() {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (TextUtils.isEmpty(regId)) {
// Automatically registers application on startup.
GCMRegistrar.register(this, Config.GCM_SENDER_ID);
} else {
// Get the correct GCM key for the user. GCM key is a somewhat non-standard
// approach we use in this app. For more about this, check GCM.TXT.
final String gcmKey = AccountUtils.hasActiveAccount(this) ?
AccountUtils.getGcmKey(this, AccountUtils.getActiveAccountName(this)) : null;
// Device is already registered on GCM, needs to check if it is
// registered on our server as well.
if (ServerUtilities.isRegisteredOnServer(this, gcmKey)) {
// Skips registration.
LOGI(TAG, "Already registered on the GCM server with right GCM key.");
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// hence the use of AsyncTask instead of a raw thread.
mGCMRegisterTask = new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
LOGI(TAG, "Registering on the GCM server with GCM key: "
+ AccountUtils.sanitizeGcmKey(gcmKey));
boolean registered = ServerUtilities.register(BaseActivity.this,
regId, gcmKey);
// At this point all attempts to register with the app
// server failed, so we need to unregister the device
// from GCM - the app will try to register again when
// it is restarted. Note that GCM will send an
// unregistered callback upon completion, but
// GCMIntentService.onUnregistered() will ignore it.
if (!registered) {
LOGI(TAG, "GCM registration failed.");
GCMRegistrar.unregister(BaseActivity.this);
} else {
LOGI(TAG, "GCM registration successful.");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
mGCMRegisterTask = null;
}
};
mGCMRegisterTask.execute(null, null, null);
}
}
}
开发者ID:gdg-bh,项目名称:AppDevFestSudeste2015,代码行数:57,代码来源:BaseActivity.java
示例3: sync
import com.google.samples.apps.iosched.gcm.ServerUtilities; //导入依赖的package包/类
/**
* Create a copy of current pending actions and delegate the
* proper sync'ing to the concrete subclass on the method syncImpl.
*
*/
public boolean sync() {
// get data pending sync:
Cursor scheduleData = mContext.getContentResolver().query(
MySchedule.buildMyScheduleUri(mContext, mAccountName), MyScheduleQuery.PROJECTION,
null, null, null);
if (scheduleData == null) {
return false;
}
// Although we have a dirty flag per item, we need all schedule to sync, because it's all
// sync'ed at once to a file on AppData folder. We only use the dirty flag to decide if
// the local content was changed or not. If it was, we replace the remote content.
boolean hasPendingLocalData = false;
ArrayList<UserAction> actions = new ArrayList<UserAction>();
while (scheduleData.moveToNext()) {
UserAction userAction = new UserAction();
userAction.sessionId = scheduleData.getString(MyScheduleQuery.SESSION_ID);
Integer inSchedule = scheduleData.getInt(MyScheduleQuery.IN_SCHEDULE);
if (inSchedule == 0) {
userAction.type = UserAction.TYPE.REMOVE_STAR;
} else {
userAction.type = UserAction.TYPE.ADD_STAR;
}
userAction.requiresSync = scheduleData.getInt(MyScheduleQuery.DIRTY_FLAG) == 1;
actions.add(userAction);
if (!hasPendingLocalData && userAction.requiresSync) {
hasPendingLocalData = true;
}
}
scheduleData.close();
Log.d(TAG, "Starting Drive AppData sync. hasPendingData = " + hasPendingLocalData);
boolean dataChanged = syncImpl(actions, hasPendingLocalData);
if (hasPendingLocalData) {
resetDirtyFlag(actions);
// Notify other devices via GCM
ServerUtilities.notifyUserDataChanged(mContext);
}
if (dataChanged) {
LOGD(TAG, "Notifying changes on paths related to user data on Content Resolver.");
ContentResolver resolver = mContext.getContentResolver();
for (String path : ScheduleContract.USER_DATA_RELATED_PATHS) {
Uri uri = ScheduleContract.BASE_CONTENT_URI.buildUpon().appendPath(path).build();
resolver.notifyChange(uri, null);
}
mContext.sendBroadcast(ScheduleWidgetProvider.getRefreshBroadcastIntent(mContext, false));
}
return dataChanged;
}
开发者ID:gdg-bh,项目名称:AppDevFestSudeste2015,代码行数:60,代码来源:AbstractUserDataSyncHelper.java
注:本文中的com.google.samples.apps.iosched.gcm.ServerUtilities类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论