可以通过 Lollipop 和 marshmallow 的数据意图获得响应,但不能通过 kitkat 获得响应。使用棉花糖时可以使用响应代码,但数据意图为 kitkat 返回 null。
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();
}
}
为 kitkat 调用 onActivityResult 但意图数据为空
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();
}
}