在 Android 的片段中集成 Braintree Dropin 时出错

Error Integrating Braintree Dropin In a Fragment in Android

我需要有关 Android 片段内集成的帮助,当代码在 Activity 中实现时它工作正常,但在我的案例中,我需要在片段中实现它。

我正在尝试从 Fragment 调用 dropin ui 但无法调用。

我遵循的步骤:- 1) 我使用 get_braintree_token(rootview.getContext()) .

获取了 braintree 令牌

2) 获得令牌后,我将其传递给 onBraintreeSubmit(braintreeToken ,viewb) 3)当它到达 onBraintreeSubmit 函数中的 startActivityForResult() 时,BrainTree UI 没有膨胀。它直接移动到 onActivityResult() with resultcode 1 and some random Request code . 我在下面写了我的函数。

public View onCreateView(LayoutInflater inflater, ViewGroup   container,Bundle savedInstanceState) {

rootview = inflater.inflate(R.layout.fragment_map, container, false);
get_braintree_token(rootview.getContext());
return rootview;
  }
public void get_braintree_token(final Context viewb)
{

StringRequest stringRequest = new StringRequest(Request.Method.GET, "My    server URL",    new Response.Listener<String>() {
                    @Override
                    public void onResponse(String     response) {

                    braintreeToken = response.toString();
                    Log.e("Braintreetoken","token is:"+braintreeToken);

                    onBraintreeSubmit(braintreeToken, viewb);

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            braintreeToken = null;
        }
    });
// Add the request to the RequestQueue.
    requestQueue.add(stringRequest);

}


public void onBraintreeSubmit(String token, Context c) {
    Log.e("tokenreceived",token);
    DropInRequest dropInRequest = new  DropInRequest();

    dropInRequest.clientToken(token);
    Intent drop = dropInRequest.getIntent(c);
    startActivityForResult(drop, BRAINTREE_REQUEST_CODE);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == BRAINTREE_REQUEST_CODE) {
        if (resultCode == 1) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            // use the result to update your UI and send the payment method nonce to your server
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // the user canceled
        } else {
            // handle errors here, an exception may be available in
            Exception error = (Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR);
        }
    }
} 

传递令牌值,这里传递了一个 Json 响应,这是创建问题,因此从响应中提取令牌并将其传递给 braintree 方法,而不是传递 json 响应。