我想在通过亚马逊进行的 inapppurchasing SamplepurchaseListener.java 的 onpurchaseresponse() 中使用共享偏好
i want to use shared preference in the onpurchaseresponse() of SamplepurchaseListener.java of inapppurchasing via amazon
当案例成功时,我想编辑变量值,然后我想在我的项目的其他 class 中使用这个值。
我该怎么做?
请给我建议?
switch (status) {
case SUCCESSFUL:
SamplePurchasingListener.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE).edit();
editor.putBoolean("PREMIUM", true); // Storing boolean - true/false
editor.commit();
}
});
final Receipt receipt = response.getReceipt();
iapManager.setAmazonUserId(response.getUserData().getUserId(), response.getUserData().getMarketplace());
Log.d(TAG, "onPurchaseResponse: receipt json:" + receipt.toJSON());
iapManager.handleReceipt(response.getRequestId().toString(), receipt, response.getUserData());
iapManager.refreshLevel2Availability();
break;
case ALREADY_PURCHASED:
Log.i(TAG,
"onPurchaseResponse: already purchased, you should verify the entitlement purchase on your side and make sure the purchase was granted to customer");
break;
如果您只想从另一个 class 中检索值,为什么不直接从首选项中获取呢?像这样:
SharedPreferences sp = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE);
boolean premium = sp.getBoolean("PREMIUM", false);
if(premium) { ...
如果之前没有存储值,方法将return "false"。
可能我没看懂你的问题。
当案例成功时,我想编辑变量值,然后我想在我的项目的其他 class 中使用这个值。 我该怎么做? 请给我建议?
switch (status) {
case SUCCESSFUL:
SamplePurchasingListener.this.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
SharedPreferences.Editor editor = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE).edit();
editor.putBoolean("PREMIUM", true); // Storing boolean - true/false
editor.commit();
}
});
final Receipt receipt = response.getReceipt();
iapManager.setAmazonUserId(response.getUserData().getUserId(), response.getUserData().getMarketplace());
Log.d(TAG, "onPurchaseResponse: receipt json:" + receipt.toJSON());
iapManager.handleReceipt(response.getRequestId().toString(), receipt, response.getUserData());
iapManager.refreshLevel2Availability();
break;
case ALREADY_PURCHASED:
Log.i(TAG,
"onPurchaseResponse: already purchased, you should verify the entitlement purchase on your side and make sure the purchase was granted to customer");
break;
如果您只想从另一个 class 中检索值,为什么不直接从首选项中获取呢?像这样:
SharedPreferences sp = getSharedPreferences(MY_PREFS_NAME, MODE_WORLD_READABLE);
boolean premium = sp.getBoolean("PREMIUM", false);
if(premium) { ...
如果之前没有存储值,方法将return "false"。 可能我没看懂你的问题。