问题
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