我在整合谷歌的应用内结算方面遇到了很多麻烦.
我有一个应该进行应用内结算的活动.我正在使用startActivity方法从我的主要活动中调用此活动.
Intent i = new Intent();
i.setComponent(new ComponentName("com.mypackage.mainactivity","com.mypackage.mainactivity.InAppBillingActivity"));
startActivity(i);
并调用mBillingService.requestPurchase(“android.test.purchased”,“10”)
在In-App-Billing活动的onCreate方法中.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mHandler = new Handler();
mInAppBillingPurchaseObserver = new InAppBillingPurchaseObserver(mHandler);
mBillingService = new BillingService();
mBillingService.setContext(this);
ResponseHandler.register(mInAppBillingPurchaseObserver);
boolean supported = mBillingService.checkBillingSupported();
System.out.println("onCreate.isBillingSupported " + supported);
if(supported) {
Log.i("AJ", "Calling requestPurchase");
mBillingService.requestPurchase("android.test.purchased", "10");
}
}
由于In-App-Billing对服务器进行异步调用,所以我何时应该调用finish()来返回主活动.但我不希望活动结束,我仍然需要异步调用的结果.那么我该如何处理呢.
我在向服务器发送请求后调用了finish().但后来我得到了这个例外:
05-29 03:11:58.897: ERROR/ActivityThread(3549): Activity com.mypackage.mainactivity.InAppBillingActivity has leaked ServiceConnection com.mypackage.mainactivity.BillingService@45b0ad50 that was originally bound here
05-29 03:11:58.897: ERROR/ActivityThread(3549): android.app.ServiceConnectionLeaked: Activity com.mypackage.mainactivity.InAppBillingActivity has leaked ServiceConnection com.mypackage.mainactivity.BillingService@45b0ad50 that was originally bound here
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread$PackageInfo$ServiceDispatcher.(ActivityThread.java:1158)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread$PackageInfo.getServiceDispatcher(ActivityThread.java:1053)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ContextImpl.bindService(ContextImpl.java:908)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.mypackage.mainactivity.BillingService.bindToMarketBillingService(Unknown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.mypackage.mainactivity.BillingService.access$000(Unknown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.mypackage.mainactivity.BillingService$BillingRequest.runRequest(Unknown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.mypackage.mainactivity.BillingService.checkBillingSupported(Unknown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.mypackage.mainactivity.InAppBillingActivity.onCreate(Unknown Source)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread.access$2500(ActivityThread.java:129)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.os.Looper.loop(Looper.java:143)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at android.app.ActivityThread.main(ActivityThread.java:4701)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at java.lang.reflect.Method.invoke(Method.java:521)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-29 03:11:58.897: ERROR/ActivityThread(3549): at dalvik.system.NativeStart.main(Native Method)
它没有退出应用程序,但它停止了InAppBillingActivity.
任何帮助都非常感谢.
谢谢,
阿卡什
P.S.:My Old Question,尚未解决…..
解决方法:
你应该使用startActivityForResult()
Context.StartActivityforResult URL
通过这种方式,您可以开始计费,让它执行异步回调,当它收到“成功”或“失败”时,您可以调用finish();发回结果.
In App Billing的另一个教程是:Simple InApp Billing,这为您提供了第二个视角,可能会帮助您了解BillingService正在尝试实现的目标.
编辑
对于’Simple InApp Billin’的错误:
您在购买时收到错误,您可以在结算服务中找到错误的结果,否则在结算助手中您可以更新方法以停止此操作:
protected static void verifyPurchase(String signedData, String signature) {
ArrayList<VerifiedPurchase> purchases = BillingSecurity.verifyPurchase(signedData, signature);
if(purchases != null && !purchases.isEmpty()){ // Check for NPE
latestPurchase = purchases.get(0);
confirmTransaction(new String[]{latestPurchase.notificationId});
} else {
Log.d(TAG, "BillingHelper.verifyPurchase error. purchases was null");
}
if(mCompletedHandler != null){
mCompletedHandler.sendEmptyMessage(0);
} else {
Log.e(TAG, "verifyPurchase error. Handler not instantiated. Have you called setCompletedHandler()?");
}
}
标签:java,android,billing
来源: https://codeday.me/bug/20190710/1420182.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。