ข้อผิดพลาดในการเรียกเก็บเงินในแอป: ไม่สามารถซื้อสินค้าได้, การตอบสนองข้อผิดพลาด 5 ข้อผิดพลาดของนักพัฒนา

ฉันตั้งค่าบริการเรียกเก็บเงินในแอปโดยมีอุปกรณ์สิ้นเปลือง 2 ชิ้นและอีก 1 ชิ้นใช้ไม่ได้

สำหรับผู้ที่ไม่บริโภค ฉันกำลังตรวจสอบรายการซื้อ และหากสินค้ามีเจ้าของแล้ว ฉันต้องการให้ผู้ใช้งดเว้นจากการซื้ออีกครั้งและมอบสิทธิประโยชน์ให้แทน ฉันมีสองคลาส: Guess.java (ไฟล์ Launcher) และ Purchase.java (ไฟล์ตั้งค่าการเรียกเก็บเงินในแอป)

ภายใน Guess.java

Intent intent = new Intent(Guess.this,Purchase.class);
intent.putExtra("buy_2x", "buy_2x");
startActivity(intent);

buy_2x เป็นสินค้าที่ไม่สิ้นเปลือง (ตัวเลือกการซื้อคือ 2 ในโค้ดด้านล่าง ในขณะที่วัสดุสิ้นเปลืองเรียกว่าตัวเลือกการซื้อ 0 และ 1) ที่ฉันอ้างถึง ภายใน Purchase.java รหัสจะเป็นดังนี้

public class Purchase extends Activity {

    IInAppBillingService mService;
    private Bundle extras;
    private int add=0;//add coins to the kitty


    private int buying_choice;

    private String ITEM_SKU_SELECTION;


    private static final String TAG = "com.apps.guess.inappbilling";
    IabHelper mHelper;

    private ServiceConnection mServiceConn;

    @Override 
    public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

        String base64EncodedPublicKey = "<64-char> long";

        Intent intent = getIntent();
            String buy2x_recd =intent.getExtras().getString("buy_2x"); 

        //this is a class that contains static variables and I am using choices
            //0,1,2...choice 2 is for the non-consumable buy_2x
        if(UserData.getBuying_choice()!=2) ITEM_SKU_SELECTION = selectbuyingChoice(UserData.getBuying_choice());

            //callService() method referred below 
        if(buy2x_recd.equalsIgnoreCase("buy_2x"))callService();

        mHelper = new IabHelper(this, base64EncodedPublicKey);
        mHelper.startSetup(new 
                IabHelper.OnIabSetupFinishedListener() {
                      public void onIabSetupFinished(IabResult result) 
                  {
                        if (!result.isSuccess()) {
                        Toast.makeText(getApplicationContext(), "In-app Billing setup failed: = ", Toast.LENGTH_LONG).show();
                        Log.d(TAG, "In-app Billing setup failed: ");
                      } else {             
                            Log.d(TAG, "In-app Billing is set up OK");
                            mHelper.launchPurchaseFlow(Purchase.this, ITEM_SKU_SELECTION, 10001,mPurchaseFinishedListener, "");
                            mHelper.enableDebugLogging(true, TAG);
                  }
                   }
                });



    }//onCreate() ends

    public void callService(){
        mServiceConn = new ServiceConnection() 
        {
        @Override
            public void onServiceConnected(ComponentName name,
                    IBinder service) {
                  mService = IInAppBillingService.Stub.asInterface(service);
                    Log.d("TEST", "mService ready to go!");
                    checkownedItems();  
        }

            @Override
            public void onServiceDisconnected(ComponentName name) {
                 mService = null;
            }
        };

        bindService(new Intent("com.android.vending.billing.InAppBillingService.BIND"), mServiceConn, Context.BIND_AUTO_CREATE);
        }

     private void checkownedItems()
        {

    try {
        Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);

        int response = ownedItems.getInt("RESPONSE_CODE");
        if (response == 0) {
           ArrayList<String> ownedSkus =
              ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
           ArrayList<String>  purchaseDataList =
              ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
           ArrayList<String>  signatureList =
              ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE");
           String continuationToken = 
              ownedItems.getString("INAPP_CONTINUATION_TOKEN");

           for (int i = 0; i < purchaseDataList.size(); ++i) {
              String purchaseData = purchaseDataList.get(i);
              String signature = signatureList.get(i);
              String sku = ownedSkus.get(i);

              if(sku.equalsIgnoreCase("buy_2x"))
              {

                AlertDialog.Builder builder = new AlertDialog.Builder(Purchase.this);
                builder.setTitle("Purchased Already");
                builder.setMessage("You have already purchased the 2X option. Do you want to enable it?");

                builder.setPositiveButton("Yes!", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog1, int which) {
                        Toast.makeText(getApplicationContext(), "You have decided to double your gains!.Please wait...", Toast.LENGTH_LONG).show();

                        int double_2x_value=2*getResources().getIntArray(R.array.start_parameters)[2];
                        UserData.writeData(""+double_2x_value, Purchase.this, UserData.get2XFile());
                        UserData.setWinningValue(""+double_2x_value);

                        UserData.writeData("true", Purchase.this, UserData.getDoubleXPurchaseFile());
                        UserData.setBuy2X(true);

                        UserData.setBuying_choice(0);
                        dialog1.dismiss();

                         Intent intent = new Intent(Purchase.this, com.glambleapps.guesstheword.Guess.class);
                         startActivity(intent);

                        }});

                builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog1, int which) {
                        dialog1.dismiss();
                        }});
                AlertDialog alert = builder.create();
                alert.show();
                  break;
              }


              // do something with this purchase information
              // e.g. display the updated list of products owned by user
           } 

           // if continuationToken != null, call getPurchases again 
           // and pass in the token to retrieve more items
        }

        else {
            Toast.makeText(Purchase.this, "No 2X purchase available on your device",Toast.LENGTH_LONG).show();
            ITEM_SKU_SELECTION=selectbuyingChoice(2);
        } 


    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

    private String selectbuyingChoice(int buying_choice2) {
        String ITEM_SKU_SELECTION=null;
        switch(buying_choice2){
        case 0:
            ITEM_SKU_SELECTION = "buy_200_coins";
            add = 200;
            Toast.makeText(getApplicationContext(), "You have decided to purchase 200 Coins.Please wait...", Toast.LENGTH_LONG).show();
            break;

        case 1:
            ITEM_SKU_SELECTION = "buy_1200_coins";
            add = 1200;
            Toast.makeText(getApplicationContext(), "You have decided to purchase 1200 Coins.Please wait...", Toast.LENGTH_LONG).show();
            break;

        case 2:
            ITEM_SKU_SELECTION = "buy_2x";
            add = 0;
            Toast.makeText(getApplicationContext(), "You have decided to double your winnings!.Please wait...", Toast.LENGTH_LONG).show();
            break;

        default:
            Toast.makeText(getApplicationContext(), "NO BUYING CHOICE", Toast.LENGTH_SHORT).show();
            break;

        }

        //Toast.makeText(getApplicationContext(), "ITEM_SKU_SELECTION = "+ITEM_SKU_SELECTION, Toast.LENGTH_SHORT).show();
        return ITEM_SKU_SELECTION;

    }

    IabHelper.OnConsumeFinishedListener mConsumeFinishedListener =
              new IabHelper.OnConsumeFinishedListener() {
               public void onConsumeFinished(Purchase purchase, 
                     IabResult result) {

             if (result.isSuccess()) {               


                 int total =add+Integer.parseInt(UserData.getCoins_remaining());

                 if(!(ITEM_SKU_SELECTION.equalsIgnoreCase("buy_2x")))
                 Toast.makeText(getApplicationContext(), "Successful purchase done of "+add+" Guess-Coins!", Toast.LENGTH_LONG).show();



                 if(ITEM_SKU_SELECTION.equalsIgnoreCase("buy_2x")){

                     int double_2x_value=2*getResources().getIntArray(R.array.start_parameters)[2];
                     Toast.makeText(getApplicationContext(), "2X - Double your winnings! purchase is successful.", Toast.LENGTH_LONG).show();

                     UserData.setWinningValue(""+double_2x_value);


                 }

                 add=0;
                 Intent intent = new Intent(Purchase.this, Guess.class);
                 startActivity(intent);

             } else {
                 Toast.makeText(getApplicationContext(), "NO PURCHASE DONE", Toast.LENGTH_LONG).show();
                 Intent intent = new Intent(Purchase.this, Guess.class);
                 startActivity(intent);

             }
          }
        };

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mHelper != null) mHelper.dispose();
        mHelper = null;

        if(mServiceConn != null)
        {
            unbindService(mServiceConn);
            mServiceConn=null;
        }

    }

    public void consumeItem() {
        mHelper.queryInventoryAsync(mReceivedInventoryListener);
    }


    IabHelper.QueryInventoryFinishedListener mReceivedInventoryListener 
       = new IabHelper.QueryInventoryFinishedListener() {
           public void onQueryInventoryFinished(IabResult result,
              Inventory inventory) {


              if (result.isFailure()) {

                  Intent intent = new Intent(Purchase.this, Guess.class);
                  startActivity(intent);

              } else {
                     mHelper.consumeAsync(inventory.getPurchase(ITEM_SKU_SELECTION), mConsumeFinishedListener);
              }
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
          if (!mHelper.handleActivityResult(requestCode, resultCode, data)) {     
            super.onActivityResult(requestCode, resultCode, data);
          }

          if (resultCode == RESULT_CANCELED) {
              Toast.makeText(PurchaseActivity.this,"Sorry, you have canceled your coins purchase.",Toast.LENGTH_SHORT).show();
          }


    }

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener 
    = new IabHelper.OnIabPurchaseFinishedListener() {
    public void onIabPurchaseFinished(IabResult result, 
                    Purchase purchase) 
    {
       if (result.isFailure()) {

             Intent intent = new Intent(Purchase.this, Guess.class);
             startActivity(intent);

          return;
     }      
     else if (purchase.getSku().equals(ITEM_SKU_SELECTION)) {consumeItem();
    }

   }
};





}//class ends 

ฉันได้รับคำเตือนต่อไปนี้:

Implicit intents with startService are not safe: Intent { act=com.android.vending.billing.InAppBillingService.BIND } android.content.ContextWrapper.bindService:517  Purchase.callService:107  Purchase.onCreate:68 

ข้อผิดพลาดมีดังนี้:

IabHelper(25782): In-app billing error: Unable to buy item, Error response: 5:Developer Error

UserData.java เก็บค่าบางค่าและเขียนข้อมูลในไฟล์ข้อความ พวกเขาไม่มีปัญหา

ปัญหานี้คืออะไร? กรุณาช่วย. ขอบคุณ


person Ganesh Hegde    schedule 10.04.2014    source แหล่งที่มา
comment
คุณพบวิธีแก้ปัญหาสำหรับสิ่งนี้แล้วหรือยัง? แม้ว่าฉันกำลังเผชิญกับปัญหาเดียวกัน   -  person keen    schedule 26.07.2014
comment
สวัสดี ประสบปัญหาเดียวกัน มีคนบอกว่าเป็นเพราะ APK ที่ไม่ได้ลงชื่ออย่างถูกต้อง แต่ฉันได้อัปโหลดรุ่นไปยัง Google Play Alpha และฉันกำลังทดสอบรุ่นที่มีอยู่ ความช่วยเหลือใด ๆ ที่จะได้รับการชื่นชม   -  person Golan Shay    schedule 27.02.2017


คำตอบ (2)


คุณกำลังพยายามซื้อรายการที่บันทึกไว้ในอุปกรณ์ของคุณด้วยบัญชีนักพัฒนาซอฟต์แวร์ GooglePlay ของคุณหรือไม่

Google ไม่อนุญาต คุณควรใช้อันอื่น

ในคอนโซลนักพัฒนาซอฟต์แวร์ ให้ไปที่การตั้งค่าบัญชีและเพิ่มบัญชีบางบัญชีเพื่อทดสอบ จากนั้นเข้าสู่ระบบด้วยหนึ่งในนั้นแล้วลองซื้อสินค้า คุณควรจะสามารถบรรลุเป้าหมายได้

แก้ไข:

จากการตรวจสอบเอกสาร ฉันพบว่าคุณต้องทดสอบด้วย apk ที่ลงนามที่ถูกต้อง http://developer.android.com/google/play/billing/billing_reference.html

person dlao    schedule 03.10.2014

คุณเพียงแค่ต้องให้ PAY_THROUGH_...(ร้านค้า evrey ที่คุณไม่เหมาะสม) ใน Manifest: ตัวอย่างเช่นสำหรับร้าน cafebazar : หรือสำหรับ play store : ....

person sadeq soft    schedule 25.03.2020
comment
โปรดอธิบายคำตอบของคุณอย่างละเอียด ฉันไม่สามารถหัวหรือก้อยของมันได้ นอกจากนี้ โปรดใช้การจัดรูปแบบที่ให้มาเพื่อแยกโค้ดออกจากข้อความปกติ - person Tarick Welling; 25.03.2020