بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
پرسش و پاسخ
مشکل درون پرداخت کافه بازار
مدیریت گفتگو
آخرین تغییر: 11 سال پیش
سلام ، من تا جایی که جستجو کردم چند تاپیک مشابه با مشکل خودم پیدا کردم ولی اونها هم به نتیجه نرسیدن متاسفانه،
مشکل اینجاست که گاهی اوقات که روی دکمه آپگرید کلیک میشه، این ارور در لاگ ثبت میشه :
java.lang.IllegalStateException: Can't start async operation (launchPurchaseFlow) because another async operation(refresh inventory) is in progress.
لازم به ذکره متد on destroy رو قرار دادم و اتصال رو هم با try گذاشتم ولی همچنان مشکل برطرف نشده
پاسخها 1
شما باید بخش پیاده سازی API را مطالعه بفرمایید
پاسخ برگستی در قالب یک json به متد onActivityResult برگشت داده می شود:
قبلا سیستم محصولات مصرفی را از روی این مستندات پیاده سازی کرده بودم . شاید بدردت بخوره :
public class API extends Activity {
Button kharid;
Button masraf;
TextView coin_txt;
int Coin = 0;
IInAppBillingService mService;
Thread thread;
Bundle buyIntentBundle;
String token;
String sharedKey;
SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.me);
coin_txt = (TextView) findViewById(R.id.coin);
kharid = (Button) findViewById(R.id.kharid);
masraf = (Button) findViewById(R.id.masraf);
//retrieve Coin
prefs = getSharedPreferences("MyPrefs_api", Context.MODE_PRIVATE);
Coin = prefs.getInt(sharedKey, Coin);
coin_txt.setText(Coin + " Coin");
masraf.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (Coin >= 50) {
Coin -= 50;
coin_txt.setText(Coin + " Coin");
}else if (Coin <= 0) {
Toast.makeText(getApplicationContext(), "Coin is finished! Buy some more", Toast.LENGTH_SHORT).show();
}
Editor editor = prefs.edit();
editor.putInt(sharedKey, Coin);
editor.commit();
}
});
thread = new Thread(new Runnable() {
@Override
public void run() {
bindService(new Intent("ir.cafebazaar.pardakht.InAppBillingService.BIND")
, mServiceConn, Context.BIND_AUTO_CREATE);
}
});thread.start();
kharid.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
thread = new Thread(new Runnable() {
@Override
public void run() {
try {
buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
"api2", "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzsdfsfdfJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
startIntentSenderForResult(pendingIntent.getIntentSender(),
1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
Integer.valueOf(0));
} catch (RemoteException e) {
Toast.makeText(getApplicationContext(), "opps ", Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (SendIntentException e) {
Toast.makeText(getApplicationContext(), "opps startIntentSenderForResult", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
thread.start();
}
});
}
@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");
token = jo.getString("purchaseToken");
thread = new Thread(new Runnable() {
@Override
public void run() {
try {
int response = mService.consumePurchase(3, getPackageName(), token);
} catch (RemoteException e) {
Toast.makeText(getApplicationContext(), "Failed to Consume produce", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});thread.start();
Coin += 100;
coin_txt.setText(Coin + " Coin");
Editor editor = prefs.edit();
editor.putInt(sharedKey, Coin);
editor.commit();
}
catch (JSONException e) {
Toast.makeText(getApplicationContext(), "Failed to parse purchase data.", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mServiceConn != null) {
unbindService(mServiceConn);
}
}
ServiceConnection mServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IInAppBillingService.Stub.asInterface(service);
}
};
}
نظرات
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .
ویرایش
پیام
نظرات