据谷歌实现应用内结算的文件,这就是谷歌将同步发送响应代码的响应包映射到RESPONSE_CODE关键 In-app Billing Reference的Android应用内结算处理谷歌服务器响应代码
现在是一个整数我有这样的代码在我的应用程序
@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");
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
我怎么可以处理谷歌响应代码,例如
if (responsecode == 7) do somthing
我tryed使这个
if(resultCode == RESULT_OK || resposeCode == 7) do somthing
和
if(resultCode == RESULT_OK || resultCode == 7) do somthing
但当然,我在这里是因为什么工作对我来说
更新:
public class Test extends Activity {
IInAppBillingService mService;
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);
}
};
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Intent serviceIntent =
new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending");
bindService(serviceIntent, mServiceConn, Context.BIND_AUTO_CREATE);
Typeface font = Typeface.createFromAsset(getAssets(), "fontawesome-webfont.ttf");
b1 = (Button)findViewById(R.id.button1);
b2 = (Button)findViewById(R.id.button3);
b1.setTypeface(font);
b2.setTypeface(font);
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
buy(id);
}}
@Override
public void onDestroy() {
super.onDestroy();
if (mService != null) {
unbindService(mServiceConn);
}
}
public void buy(String id) {
try {
Bundle buyIntentBundle = mService.getBuyIntent(3, getPackageName(), selected, "inapp", "bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ");
PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
this.startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
} catch (RemoteException e) {
e.printStackTrace();
} catch (IntentSender.SendIntentException e) {
e.printStackTrace();
}
}
@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");
Toast.makeText(getApplication(), "request true", Toast.LENGTH_LONG).show();
if (resultCode == RESULT_OK) {
Toast.makeText(getApplication(), "result true ", Toast.LENGTH_LONG).show();
if (responseCode == 0){
Toast.makeText(getApplication(), " response = 0", Toast.LENGTH_LONG).show();
}
else if(responseCode == 7){
Toast.makeText(getApplication(), "response = 7 ", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplication(), "error", Toast.LENGTH_LONG).show();
}
}
}
}
}
日志文件:它是给购买者成功和下载项目,但下次我尝试buyint之前购买同样的东西ENT开始,它的崩溃,给这个错误
这段代码有什么错误给下一次
this.startIntentSenderForResult(pendingIntent.getIntentSender(), 1001, new Intent(), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
java.lang.NullPointerException
at com.app.inapp.bill.Test.buy(Test.java:258)
at com.app.inapp.bill.Test$3.onClick(Test.java:226)
at android.view.View.performClick(View.java:4651)
at android.view.View$PerformClick.run(View.java:19310)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
正是你想要什么? –
如果项目已拥有,我想为用户下载而不再购买它,因为他已经拥有它 – hasd11
我已经更新了我的答案尝试并让我知道。 –