本文介绍了从我的Android应用程序复位成就/排行榜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以从我的,用于与谷歌玩游戏服务的Android应用程序重置我的成就/排行榜的结果?
Can I reset my achievements/leaderboard result from my Android application that is used with Google Play Game Services?
推荐答案
是的,这是可能的,从测试帐户。这是一个有点棘手,所以这里的一些例子code。
Yes, this is possible from test accounts. It’s a bit tricky so here some example code.
将此你的清单:
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />
这里是实际code在应用程序执行。添加了在基于BaseGameActivity活性
And here is the actual code to be executed in the application. Added in the activity that is based on BaseGameActivity.
public void resetAchievements()
{
if( isSignedIn() )
{
String accountName = getGamesClient().getCurrentAccountName();
String scopes = getScopes();
new ResetterTask(this, accountName, scopes).execute((Void) null);
}
}
private class ResetterTask extends AsyncTask<Void, Void, Void>
{
public String mAccountName;
public String mScope;
public Context mContext;
public ResetterTask(Context con, String name, String sc)
{
mContext = con;
mAccountName = name;
mScope = sc;
}
@Override
protected Void doInBackground(Void... params)
{
try
{
String accesstoken = GoogleAuthUtil.getToken(mContext, mAccountName, mScope);
HttpClient client = new DefaultHttpClient();
//Reset leader board:
/*String leaderboardid = "theleaderboardid";
HttpPost post = new HttpPost
(
"https://www.googleapis.com"+
"/games/v1management"+
"/leaderboards/"+
leaderboardid+
"/scores/reset?access_token="+accesstoken
);*/
//Reset a single achievement like this:
/*
String acheivementid = "acheivementid";
HttpPost post = new HttpPost
(
"https://www.googleapis.com"+
"/games/v1management"+
"/achievements/"+
acheivementid+
"/reset?access_token="+accesstoken
);*/
//This resets all achievements:
HttpPost post = new HttpPost
(
"https://www.googleapis.com"+
"/games/v1management"+
"/achievements"+
"/reset?access_token="+accesstoken
);
client.execute(post);
Log.w(LogTag, "Reset achievements done.");
}
catch(Exception e)
{
Log.e(LogTag, "Failed to reset: " + e.getMessage(), e);
}
return null;
}
@Override
protected void onPostExecute(Void result)
{
//Launch activity to refresh data on client.
//NOTE: Incremental achievements will look like they are not reset.
//However, next time you and some steps it will start from 0 and
//gui will look ok.
startActivityForResult(getGamesClient().getAchievementsIntent(), 0);
}
}
这篇关于从我的Android应用程序复位成就/排行榜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!