我正在使用AndroidBillingLibrary来实现应用内计费。购买项目应禁用所有活动中的广告。但是当我测试我的应用程序时(第一个项目是“android.test.purchase”,然后是真正的项目)发生以下情况:购买广告被禁用后,但重新启动应用程序后广告再次出现。
项目发布在开发者控制台中,当我使用测试帐户 Google Play 购买项目时说一切正常。
购买按钮位于我的应用程序的设置中。以下是部分代码:
public class PreferencesActivity extends SherlockPreferenceActivity {
public final static String PUBLIC_KEY = "my public key";
public final static String ANDROID_ADS_ITEM = "ads.buy";
private AbstractBillingObserver billingObserver;
...
@Override protected void onDestroy(){
BillingController.unregisterObserver(billingObserver);
super.onDestroy();
}
private void adsDisable(){
final Preference adsDisable = (Preference) findPreference("disableAds");
billingObserver = new AbstractBillingObserver(this){
public void onRequestPurchaseResponse(String itemId, ResponseCode response){
}
public void onPurchaseStateChanged(String itemId, PurchaseState state){
}
public void onBillingChecked(boolean supported){
if(!supported)
adsDisable.setEnabled(false);
else if(!billingObserver.isTransactionsRestored())
BillingController.restoreTransactions(PreferencesActivity.this);
}
public void onSubscriptionChecked(boolean supported) {
// TODO Auto-generated method stub
}
};
BillingController.setConfiguration(new IConfiguration(){
public String getPublicKey(){
return PUBLIC_KEY;
}
public byte[] getObfuscationSalt(){
return new byte[]{ 41, -90, -116, -41, 66, -53, 122, -110, -127, -96, -88, 77, 127, 115, 1, 73, 57, 110, 48, -116 };
}
});
BillingController.registerObserver(billingObserver);
BillingController.checkBillingSupported(this);
adsDisable.setOnPreferenceClickListener(new OnPreferenceClickListener(){
public boolean onPreferenceClick(Preference preference){
BillingController.requestPurchase(PreferencesActivity.this, ANDROID_ADS_ITEM, true, null);
return false;
}
});
boolean purchased = BillingController.isPurchased(this, ANDROID_ADS_ITEM);
if(purchased){
adsDisable.setTitle(R.string.disableAdsYes_prefs); adsDisable.setEnabled(false);
}
}
这就是我尝试禁用广告的方式:
public class FirstActivity extends SherlockActivity {
public final static String ANDROID_ADS_ITEM = "ads.buy";
private AdView adView;
LinearLayout layout;
@Override
public void onCreate(Bundle savedInstanceState) {
...
String adId = "my ad id";
boolean purchased = BillingController.isPurchased(this, ANDROID_ADS_ITEM);
if(purchased){
layout = (LinearLayout) findViewById(R.id.ads);
layout.removeView(layout);
} else {
adView = new AdView(this, AdSize.BANNER, adId);
layout = (LinearLayout) findViewById(R.id.ads);
layout.addView(adView);
AdRequest adRequest = new AdRequest();
adView.loadAd(adRequest);
}
}
....
}
请帮忙。对不起我的英语。