我正在尝试获取用户的购买,并且我声称我的计费服务为空,该过程正在 AsyncTask 中运行,顺便说一句,我是 Inapp 计费服务的新手,这是我的部分代码:
我的服务连接:
IInAppBillingService BillingService;
private ServiceConnection ServiceConnection = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
BillingService = null ;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
BillingService = IInAppBillingService.Stub.asInterface(service);
}
};
我的 AsyncTask 的一部分:
@Override
protected String doInBackground(Activity... params) {
final Activity mActivity = params[0];
bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), ServiceConnection, Context.BIND_AUTO_CREATE);
ConnectivityManager c = (ConnectivityManager) getSystemService(Service.CONNECTIVITY_SERVICE);
NetworkInfo NI = c.getActiveNetworkInfo();
if(NI == null || ! NI.isConnected()){
// do some stuff
}else{
Bundle purchases = null;
try {
purchases =
BillingService.
getPurchases(3, "le.wild.packagename", "inapp", null);
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(purchases.getInt("RESPONSE_CODE") == 0){
ArrayList<String> Items = purchases.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> itemsData = purchases.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
boolean o = false;
for(int i = 0 ; itemsData.size() > i ; i++){
if(Items.get(i).contains("le.wild.itemName")){
o = false;
continue;
}else{
o = true;
}
}
// do some stuff
}
我可以使用相同的方式来消费购买和获取购买意图和其他功能,只是在这里和现在它不起作用!如果您需要更多信息或任何信息,请提前致谢!
编辑 :
堆栈跟踪 :
07-22 15:58:12.830: E/AndroidRuntime(12719): FATAL EXCEPTION: AsyncTask #1
07-22 15:58:12.830: E/AndroidRuntime(12719): java.lang.RuntimeException: An error occured while executing doInBackground()
07-22 15:58:12.830: E/AndroidRuntime(12719): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
07-22 15:58:12.830: E/AndroidRuntime(12719): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.lang.Thread.run(Thread.java:856)
07-22 15:58:12.830: E/AndroidRuntime(12719): Caused by: java.lang.NullPointerException
07-22 15:58:12.830: E/AndroidRuntime(12719): at seaskyways.quadcoremanagerplus.CoresManagement$2.doInBackground(CoresManagement.java:372)
07-22 15:58:12.830: E/AndroidRuntime(12719): at seaskyways.quadcoremanagerplus.CoresManagement$2.doInBackground(CoresManagement.java:1)
07-22 15:58:12.830: E/AndroidRuntime(12719): at android.os.AsyncTask$2.call(AsyncTask.java:287)
07-22 15:58:12.830: E/AndroidRuntime(12719): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
07-22 15:58:12.830: E/AndroidRuntime(12719): ... 4 more