0

我正在使用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);
       }
    }
  ....
}

请帮忙。对不起我的英语。

4

1 回答 1

1

最有可能的问题是您在偏好活动中初始化库配置(公钥和盐)。这意味着在您打开首选项之前,不会正确配置库。引用自述文件:

此外,BillingController 需要一个 BillingController.IConfiguration 实例,从中获取验证签名消息所需的公钥和用于混淆交易的盐。提供配置的好地方是在 Application 子类中。

在这种情况下,当您isPurcharsedFirstActivity中调用时,计费控制器没有用于对数据库进行模糊处理的盐。

查看DungeonsRedux以获取在 Application 子类中设置配置的示例。

于 2012-09-10T07:09:56.340 回答