本文整理汇总了Java中com.google.android.gms.appstate.AppStateClient类的典型用法代码示例。如果您正苦于以下问题:Java AppStateClient类的具体用法?Java AppStateClient怎么用?Java AppStateClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AppStateClient类属于com.google.android.gms.appstate包,在下文中一共展示了AppStateClient类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAppStateClient
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
/**
* Returns the AppStateClient object. In order to call this method, you must have
* called @link{#setup} with a set of clients that includes CLIENT_APPSTATE.
*/
public AppStateClient getAppStateClient() {
if (mAppStateClient == null) {
throw new IllegalStateException("No AppStateClient. Did you request it at setup?");
}
return mAppStateClient;
}
示例2: start
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
public static void start(Context ctx)
{
gamesClient = new GamesClient.Builder(ctx,
new GooglePlayCallback("GAMES_CLIENT"),
new GooglePlayCallback("GAMES_CLIENT"))
.setGravityForPopups(Gravity.TOP | Gravity.CENTER_HORIZONTAL)
.setScopes(Scopes.GAMES)
.create();
appStateClient = new AppStateClient.Builder(ctx,
new GooglePlayCallback("APP_STATE_CLIENT"),
new GooglePlayCallback("APP_STATE_CLIENT"))
.setScopes(Scopes.APP_STATE)
.create();
}
示例3: onStateLoaded
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
@Override
public void onStateLoaded(int statusCode, int stateKey, byte[] data) {
LevelManager levelManager = mActivity.getGame().getLevelManager();
switch (statusCode) {
case AppStateClient.STATUS_OK:
ByteBuffer buffer = ByteBuffer.wrap(data);
levelManager.setCurrentCampaignLevel(buffer.getInt());
levelManager.setCampaignScore(buffer.getInt());
break;
default:
levelManager.setCurrentCampaignLevel(0);
levelManager.setCampaignScore(0);
}
}
示例4: getAppStateClient
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
/**
* Returns the AppStateClient object. In order to call this method, you must have
* called @link{#setup} with a set of clients that includes CLIENT_APPSTATE.
*/
public AppStateClient getAppStateClient() {
if (mAppStateClient == null) {
throw new IllegalStateException("No AppStateClient. Did you request it at setup?");
}
return mAppStateClient;
}
示例5: onStateDeleted
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
@Override
public void onStateDeleted(int statusCode, int stateKey){
JSONObject json = new JSONObject();
try{
json.put("type", STATE_CONFLICTED);
json.put("statusCode", statusCode);
json.put("stateKey", stateKey);
switch (statusCode) {
case AppStateClient.STATUS_OK:
// if data was successfully deleted from the server.
break;
case AppStateClient.STATUS_INTERNAL_ERROR:
// if an unexpected error occurred in the service
break;
case AppStateClient.STATUS_NETWORK_ERROR_OPERATION_FAILED:
// if the device was unable to communicate with the network. In this case, the operation is not retried automatically.
break;
case AppStateClient.STATUS_CLIENT_RECONNECT_REQUIRED:
// need to reconnect AppStateClient
mHelper.reconnectClients(clientTypes);
break;
default:
// error
break;
}
}catch(JSONException ex){
Log.e(TAG, "STATE_DELETED ["+statusCode+"] ["+stateKey+"] exception: "+ex.getMessage());
return;
}
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
示例6: getAppStateClient
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
protected AppStateClient getAppStateClient() {
return mHelper.getAppStateClient();
}
示例7: getAppStateClient
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
protected AppStateClient getAppStateClient()
{
return mHelper.getAppStateClient();
}
示例8: onStateLoaded
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
@Override
public void onStateLoaded(int statusCode, int stateKey, byte[] localData) {
JSONObject json = new JSONObject();
try{
json.put("type", STATE_LOADED);
json.put("status", statusCode);
switch (statusCode) {
case AppStateClient.STATUS_OK:
// Data was successfully loaded from the cloud: merge with local data.
json.put("stateKey", stateKey);
json.put("data", new String(localData));
break;
case AppStateClient.STATUS_STATE_KEY_NOT_FOUND:
// key not found means there is no saved data. To us, this is the same as
// having empty data, so we treat this as a success.
break;
case AppStateClient.STATUS_STATE_KEY_LIMIT_EXCEEDED:
// if the application already has data present in the maximum number of state keys.
break;
case AppStateClient.STATUS_NETWORK_ERROR_NO_DATA:
// can't reach cloud, and we have no local state. Warn user that
// they may not see their existing progress, but any new progress won't be lost.
break;
case AppStateClient.STATUS_NETWORK_ERROR_STALE_DATA:
// can't reach cloud, but we have locally cached data.
break;
case AppStateClient.STATUS_CLIENT_RECONNECT_REQUIRED:
// need to reconnect AppStateClient
mHelper.reconnectClients(clientTypes);
break;
case AppStateClient.STATUS_INTERNAL_ERROR:
// if an unexpected error occurred in the service.
break;
default:
// error
break;
}
}catch(JSONException ex){
Log.e(TAG, "STATE_LOADED ["+statusCode+"] ["+stateKey+"] exception: "+ex.getMessage());
return;
}
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
示例9: onStateListLoaded
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
@Override
public void onStateListLoaded(int statusCode, AppStateBuffer buffer) {
JSONObject json = new JSONObject();
try{
json.put("type", STATE_LIST_LOADED);
json.put("status", statusCode);
switch (statusCode) {
case AppStateClient.STATUS_OK:
JSONArray jsonStates = new JSONArray();
json.put("states", jsonStates);
AppState state;
JSONObject jsonState;
for(int i=0,l=buffer.getCount();i<l;i++){
state = buffer.get(i);
jsonState = new JSONObject();
if (state.hasConflict()){
jsonState.put("type", STATE_CONFLICTED);
jsonState.put("stateKey", state.getKey());
jsonState.put("version", state.getConflictVersion());
jsonState.put("localVersion", state.getLocalVersion());
jsonState.put("localData", new JSONObject(new String(state.getLocalData())));
jsonState.put("serverData", new JSONObject(new String(state.getConflictData())));
}else{
jsonState.put("type", STATE_LOADED);
jsonState.put("status", statusCode);
jsonState.put("stateKey", state.getKey());
jsonState.put("data", new JSONObject(new String(state.getLocalData())));
}
jsonStates.put(jsonState);
}
// Data was successfully loaded from the cloud: merge with local data.
break;
case AppStateClient.STATUS_NETWORK_ERROR_NO_DATA:
// can't reach cloud, and we have no local state. Warn user that
// they may not see their existing progress, but any new progress won't be lost.
break;
case AppStateClient.STATUS_NETWORK_ERROR_STALE_DATA:
// can't reach cloud, but we have locally cached data.
break;
case AppStateClient.STATUS_CLIENT_RECONNECT_REQUIRED:
// need to reconnect AppStateClient
mHelper.reconnectClients(clientTypes);
break;
case AppStateClient.STATUS_INTERNAL_ERROR:
// if an unexpected error occurred in the service.
break;
default:
// error
break;
}
}catch(JSONException ex){
Log.e(TAG, "STATE_LIST_LOADED ["+statusCode+"]["+buffer.getCount()+"] exception: "+ex.getMessage());
return;
}
buffer.close();
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
示例10: getAppStateClient
import com.google.android.gms.appstate.AppStateClient; //导入依赖的package包/类
protected AppStateClient getAppStateClient() {
return mHelper.getAppStateClient();
}