title: Android in-app billing handling google Server Response Codes
body: <p>According to google Implementing In-app Billing documentation , that's google will sends the response code synchronously as an integer mapped to the RESPONSE_CODE key in the response Bundle
  <a href="http://developer.android.com/google/play/billing/billing_reference.html#billing-codes" rel="nofollow">In-app Billing Reference</a></p>
  
  <p>now that i have this code in my app </p>
  
  <pre><code>@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();
        }
    }
  }
  }
  </code></pre>
  
  <p>how i can handling google response codes , for example </p>
  
  <pre><code>if (responsecode == 7) do somthing
  </code></pre>
  
  <p>i tryed to make this </p>
  
  <pre><code>if(resultCode == RESULT_OK || resposeCode == 7) do somthing 
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if(resultCode == RESULT_OK || resultCode == 7) do somthing 
  </code></pre>
  
  <p>but of course i'm here because nothing works for me </p>
  
  <p>update :</p>
  
  <pre><code> 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();
              }
  
  
  
  
          }
      }
  }
  }
  </code></pre>
  
  <p>logfile : it's give purchaser successful and downloaded item but next time i try buy same thing before buyintent start , it's crash and give this error<br>
  this code what give error next time </p>
  
  <pre><code>    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)
  </code></pre>