作者:mobiledu2502923007 | 来源:互联网 | 2023-09-05 13:25
我正在开发一个应用程序,它将具有用户必须付费使用的一些功能.用户可以通过单击按钮购买每个活动.为此,我使用Android应用内结算和robotmedia/AndroidBillingLibr
我正在开发一个应用程序,它将具有用户必须付费使用的一些功能.用户可以通过单击按钮购买每个活动.为此,我使用Android应用内结算和robotmedia / AndroidBillingLibrary.一切似乎在我的设备上运行良好:HTC Wildfire S(Android 2.3.5)和华硕Transformer Pad(Android 4.1.1)但我得到的信息(带有日志捕获)有时在其他设备上点击购买按钮后没有任何反应.
设备:
>三星Galaxy ACE(Android 2.3.5)
> HTC Sensation(Andorid 4.0.3)
> Xperia Neo V(Android 2.3.4)
这是日志捕获:
11-30 15:05:16.157: D/Parent Activity:(30220): Request Purchase: myitem
11-30 15:05:16.177: W/BillingService(30220): Remote billing service crashed
11-30 15:05:16.177: W/BillingService(30220): Caused by: null
这是我的活动代码的一部分:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
(...)
initViews();
initBilling();
}
@Override
protected void onDestroy()
{
BillingController.unregisterObserver(mBillingObserver);
(...)
super.onDestroy();
}
private void initBilling()
{
mBillingObserver = new BillingObserver(this);
BillingController.registerObserver(mBillingObserver);
BillingController.setConfiguration(new BillingConfiguration());
BillingController.checkBillingSupported(getApplicationContext());
if (!mBillingObserver.isTransactionsRestored()) {
BillingController.restoreTransactions(getApplicationContext());
}
Settings.updateOwnedItems(this);
}
private void showPurchaseAlert()
{
if(Settings.isOnline() && BillingController.checkBillingSupported(this) == BillingStatus.SUPPORTED)
{
(...)
((Button) alertRoot.findViewById(R.id.alert_billing_yes))
.setOnClickListener(new OnClickListener() { public void onClick(View v) { requestPurchase(BillingElement.CATALOG[number].sku); alert.cancel();}
});
}
else
{
(...)
//Purchase Alert Invisible
}
}
public void requestPurchase(String itemId)
{
Log.d("Parent Activity:", "Request Purchase: "+itemId);
BillingController.requestPurchase(getApplicationContext(), itemId, true, null);
}
在此代码中,我始终检查设备是否在线以及是否支持应用程序内结算.
Google In-App Billing中的IMarketBillingService似乎会抛出RemoteException
它在BillingService类的robotmedia / AndroidBillingLibrary中被捕获:
private void runRequest(BillingRequest request){
try {
long requestId = request.run(mService);
BillingController.onRequestSent(requestId, request);
} catch (RemoteException e) {
Log.w(this.getClass().getSimpleName(), "Remote billing service crashed");
Log.w(this.getClass().getSimpleName(), "Caused by: "+e.getCause());
// TODO: Retry?
}
}
任何人都可以解释为什么抛出RemoteException?以及如何
处理它?我做了很多测试,但在我的设备上,应用内结算始终正常.抛出RemoteException的这些设备更有趣的是,它有时只会发生.
解决方法:
它是robotmedias实现中的一个错误,您只需将服务重新绑定到您的活动即可.
hpique在他的分支中修复了它(和其他一些错误):https://github.com/hpique/AndroidBillingLibrary/commit/a62593764172d0fd650b1dca1d15c59e79aecd49
看看https://github.com/hpique/AndroidBillingLibrary