1

我正在尝试将亚马逊应用购买添加到我的安卓应用中,但遇到了一些问题。我的 PurchasingObserver 子类没有收到任何回调。以下是一些相关代码:

AmazonPurchasingObserver.java(几乎是亚马逊示例应用程序中 ButtonClickerObserver.java 的副本)

public class AmazonPurchasingObserver extends BasePurchasingObserver {

...

/**
 * Creates new instance of the ButtonClickerObserver class.
 * 
 * @param buttonClickerActivity Activity context
 */
public AmazonPurchasingObserver(final Activity activity) {
    super(activity);
    this.baseActivity = activity;
}

/**
 * Invoked once the observer is registered with the Puchasing Manager If the boolean is false, the application is
 * receiving responses from the SDK Tester. If the boolean is true, the application is live in production.
 * 
 * @param isSandboxMode
 *            Boolean value that shows if the app is live or not.
 */
@Override
public void onSdkAvailable(final boolean isSandboxMode) {
    //This method gets hit!!
    Log.v(TAG, "onSdkAvailable recieved: Response -" + isSandboxMode); 
    PurchasingManager.initiateGetUserIdRequest();
}

/**
 * Invoked once the call from initiateGetUserIdRequest is completed.
 * On a successful response, a response object is passed which contains the request id, request status, and the
 * userid generated for your application.
 * 
 * @param getUserIdResponse
 *            Response object containing the UserID
 */
@Override
public void onGetUserIdResponse(final GetUserIdResponse getUserIdResponse) {
    //This method does NOT get hit!!!
    Log.v(TAG, "onGetUserIdResponse recieved: Response -" + getUserIdResponse);
    Log.v(TAG, "RequestId:" + getUserIdResponse.getRequestId());
    Log.v(TAG, "IdRequestStatus:" + getUserIdResponse.getUserIdRequestStatus());
    new GetUserIdAsyncTask().execute(getUserIdResponse);
}

/**
 * Invoked once the call from initiateItemDataRequest is completed.
 * On a successful response, a response object is passed which contains the request id, request status, and a set of
 * item data for the requested skus. Items that have been suppressed or are unavailable will be returned in a
 * set of unavailable skus.
 * 
 * @param itemDataResponse
 *            Response object containing a set of purchasable/non-purchasable items
 */
@Override
public void onItemDataResponse(final ItemDataResponse itemDataResponse) {
    //This method does NOT get hit!!!
    Log.v(TAG, "onItemDataResponse recieved");
    Log.v(TAG, "ItemDataRequestStatus" + itemDataResponse.getItemDataRequestStatus());
    Log.v(TAG, "ItemDataRequestId" + itemDataResponse.getRequestId());
    new ItemDataAsyncTask().execute(itemDataResponse);
}

/**
 * Is invoked once the call from initiatePurchaseRequest is completed.
 * On a successful response, a response object is passed which contains the request id, request status, and the
 * receipt of the purchase.
 * 
 * @param purchaseResponse
 *            Response object containing a receipt of a purchase
 */
@Override
public void onPurchaseResponse(final PurchaseResponse purchaseResponse) {
    //This method does NOT get hit!!!
    Log.v(TAG, "onPurchaseResponse recieved");
    Log.v(TAG, "PurchaseRequestStatus:" + purchaseResponse.getPurchaseRequestStatus());
    new PurchaseAsyncTask().execute(purchaseResponse);
}

PurchasesFragment.java(将显示应用内购买的片段)

public class UpdatesFragment extends Fragment {

    ...   

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.subscriptions, container, false);

    Button btnViewSubscriptions = (Button)view.findViewById(R.id.btnViewSubscriptions);
    btnViewSubscriptions.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            PurchasingManager.initiatePurchaseRequest("testSKU");
        }
    });


    return view;
}

@Override
public void onStart() {
    super.onStart();

    AmazonPurchasingObserver observer = new AmazonPurchasingObserver(getActivity());
    PurchasingManager.registerObserver(observer);

    Set<String> skus = new HashSet<String>();
    skus.add("testSKU");
    skus.add("testSKU1");

    PurchasingManager.initiateItemDataRequest(skus);
}

最后,我的 AndroidManifest.xml

<application>
    ...
    <receiver android:name="com.amazon.inapp.purchasing.ResponseReceiver">
       <intent-filter>
           <action android:name="com.amazon.inapp.purchasing.NOTIFY" android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY" />
       </intent-filter>
    </receiver>
</application>

我究竟做错了什么?我收到日志消息说 sendItemDataRequest 和 sendPurchaseRequest 已发送,但没有得到响应。请帮忙!

4

0 回答 0