onActivityResult intent data returns null in kitkat but works in lollipop and marshmallow for UPI based payments with BHIM App

浪尽此生 提交于 2020-01-13 07:20:51

问题


Response is available through data intent for Lollipop and marshmallow but not for kitkat. The response codes are available when working with marshmallow but data intent returns null for kitkat.

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Uri data = getIntent().getData();
    if(data!=null){
    //get the parameters available from data

        String scheme = data.getScheme(); 
        String host = data.getHost(); 
        List<String> params = data.getPathSegments();
        String payeevpa = params.get(0); 
        String payeename = params.get(1); 
        String payeeamount = params.get(2); 
        String payeeref = params.get(3); 

        String UPI;
  //UPI Link creation     
        UPI = "upi://pay?pa="+payeevpa+"&pn="+payeename+"&tr="+payeeref+"&am="+payeeamount;
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW); 
        intent.setData(Uri.parse(UPI));
        Intent chooser = Intent.createChooser(intent, "Pay with...");
      //starting activity for result
        startActivityForResult(chooser, 1, null);
    }
    else {
         Intent intent = new Intent(this, ChooseLanguage.class);
         startActivity(intent);
         finish();
    }
}

onActivityResult is called for kitkat but the intent data is null

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

 //   Log.d("requestcode",requestCode+"");
 //   Log.d("resultcode",resultCode+"");
   String abc=null;
    if(data!=null){
     //intent data is available here for marshmallow
        Bundle bundle = data.getExtras();
        for (String key : bundle.keySet()) {
            Object value = bundle.get(key);
        //    Log.d("VAL", String.format("%s %s (%s)", key,
                    value.toString(), value.getClass().getName()));
            abc=value.toString();


        }
   }
    else{
      //intent data is null for kitkat
        Toast.makeText(this,"Data is Null",Toast.LENGTH_LONG).show();

    }
}

来源:https://stackoverflow.com/questions/43638148/onactivityresult-intent-data-returns-null-in-kitkat-but-works-in-lollipop-and-ma

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!