保存购买状态/按钮状态应用程序内计费android

时间:2013-09-26 14:41:04

标签: android google-play in-app

如何保存应用内结算的按钮状态?

,例如,如果某人使用Google应用内结算购买产品,则下次打开应用程序时,按钮必须处于解锁状态。我遵循了一些教程并成功添加了按钮并进行了购买,但该按钮仅保持活动一次,即,当用户离开应用时,他/她必须再次购买,这不是适当的应用内结算。

2 个答案:

答案 0 :(得分:1)

成功时,只需在SharedPreferences中保存购买状态即可。

private Boolean isUpgrade(Context context) 
{
    SharedPreferences prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE);        
    return prefs.getBoolean("upgrade", false);
}

private void setUpgrade(Context context, Boolean value) 
{
    SharedPreferences prefs = context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
    Editor edit = prefs.edit();
    edit.putBoolean("upgrade", value);        
    edit.commit();
}

答案 1 :(得分:0)

使用SharedPreferences

首先,调用以下方法获取应用程序中的共享首选项:

SharedPreferences prefs = this.getSharedPreferences("com.your.app", Context.MODE_PRIVATE);

写入/更新首选项值:

prefs.edit().putBoolean("buyState", true).commit();

要阅读偏好值:

prefs.getBoolean("buyState", false);

请注意,如果 buyState 的首选项中没有存储任何值,则 false 是要返回的默认值。

相关问题