I'm trying to use Google in app billing in my app. My code dose not have any error in eclipse but when I run it on my phone it force closes! and log cat points error to "new Thread" line. what is the problem? I'll be thankful if someone could help.
Here is my code:
in onCreate under donate button:
@Override
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
ArrayList<String> skuList = new ArrayList<String>();
skuList.add("My Selling Obj ID");
Bundle querySkus = new Bundle();
querySkus.putStringArrayList("My App’s RSA Key"
, skuList);
Bundle skuDetails;
try {
skuDetails = mService.getSkuDetails(3, getPackageName(), "inapp", querySkus);
int response = skuDetails.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> responseList
= skuDetails.getStringArrayList("DETAILS_LIST");
for (String thisResponse : responseList) {
JSONObject object = new JSONObject(thisResponse);
String sku = object.getString("productId");
String price = object.getString("price");
if (sku.equals("My Selling Obj ID"))
pool = price;
}
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bundle buyIntentBundle;
try {
buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
"My Selling Obj ID", "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(),
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SendIntentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
in onActivityResult:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);
String sku = jo.getString("productId");
Toast.makeText(Main.this, "thanks for Donation!", Toast.LENGTH_SHORT).show();
Toast.makeText(Main.this, pool,
isdonated = 1;
}
catch (JSONException e) {
//alert("Failed to parse purchase data.");
Toast.makeText(Main.this, "Donation Failed!", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
}
here is logcat errors: http://upload7.ir/imgs/2014-02/08566691322028747175.jpg