【发布时间】:2016-09-10 20:07:17
【问题描述】:
我正在尝试在我的应用中实施应用内计费,应用内计费本身运行良好。
虽然它应该只为高级用户禁用广告,但我不知何故完全禁用了它们。我将发布我的代码以更好地让您理解:
这是我的IabPurchaseFinished() 方法:
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (!verifyDeveloperPayload(info)) {
Toast.makeText(this, R.string.error_purchasing, Toast.LENGTH_LONG).show();
}
Toast.makeText(this, R.string.premium_bought, Toast.LENGTH_LONG).show();
if (info.getSku().equals("chords_premium")) {
/** salva isPremium tra SharedPreferences */
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("status", "purchased");
editor.apply();
}
}
如您所见,它将字符串值 status 保存到 SharedPreferences 为 purchased。
现在在我有广告的活动中,我是这样做的:
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.getString("status", "free");
/** gestisce le pubblicita */
if (prefs.equals("free")) {
MobileAds.initialize(getApplicationContext(), "ca-app-pub-6723047396589178/2654753246");
AdView listBanner = (AdView) findViewById(R.id.chords_list_banner);
AdRequest adRequest = new AdRequest.Builder().build();
listBanner.loadAd(adRequest);
/** carica Ad a tutto schermo */
chordsListAd = new InterstitialAd(this);
chordsListAd.setAdUnitId("ca-app-pub-6723047396589178/7447672046");
requestNewInterstitial();
chordsListAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
requestNewInterstitial();
}
});
}
如你所见,我首先检查我的*SharedPreferences*,看看是否有 "status",如果没有,我将其设置为 "free"
然后我将我的广告放在 if 声明中:
if (prefs.equals("free"))
所以,我认为如果 SharedPreferences 中的字符串是“免费的”,或者换句话说,它不是“购买的”,这意味着用户还没有在应用程序中购买,就会显示它们。
问题是,无论我是否使用有 In App 的帐户访问,广告都不会显示。关于如何解决它的任何想法?
显然,我已经使用上传到开发者控制台的签名 Apk 进行了测试,所有内容都根据谷歌的 testing In-App Billing 指南进行了设置。
【问题讨论】:
标签: java android in-app-purchase admob in-app-billing