gpt4 book ai didi

android - 从我的 Android 应用程序重置成就/排行榜

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:55:29 24 4
gpt4 key购买 nike

我可以通过与 Google Play 游戏服务一起使用的 Android 应用程序重置我的成就/排行榜结果吗?

最佳答案

是的,这可以通过测试帐户实现。这有点棘手,所以这里有一些示例代码。

将此添加到您的 list 中:

<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />

这是应用程序中要执行的实际代码。添加到基于 BaseGameActivity 的 Activity 中。

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 - 从我的 Android 应用程序重置成就/排行榜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17658732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com