[英]Unable to extract data from QR code in android
After scan QR code, app will get Event title, start date, end date and location. 扫描二维码后,应用程序将获得事件标题,开始日期,结束日期和位置。
( html code: encodeURIComponent(txt1 + "\\n" + txt2 + "\\n" + txt3 + "\\n" + txt4)
) ( html代码:
encodeURIComponent(txt1 + "\\n" + txt2 + "\\n" + txt3 + "\\n" + txt4)
)
And how to put those value into this code: 以及如何将这些值放入此代码中:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
if(result != null){
if(result.getContents()==null){
Toast.makeText(this, "You Cancelled the Scanning", Toast.LENGTH_LONG).show();
}
else {
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", ?);
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", ?);
intent.putExtra("title", ?);
intent.putExtra("eventLocation", ?);
startActivity(intent);
}
}
else{
super.onActivityResult(requestCode, resultCode, data);
}
}
You can use String.split()
to divide the string into substring. 您可以使用
String.split()
将字符串分成子字符串。 This will give you an array of strings that you can pass to the intent. 这将为您提供可以传递给意图的字符串数组。
String result = "Event title <br> start date <br> end date <br> location"
String[] info = result.split("<br>");
Calendar cal = Calendar.getInstance();
Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("beginTime", info[1].trim());
intent.putExtra("allDay", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", info[2].trim());
intent.putExtra("title", info[0].trim());
intent.putExtra("eventLocation", info[3].trim());
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.