无法从Android中的QR码提取数据

时间:2018-10-19 06:56:24

标签: java android html

扫描QR码后,应用程序将获得事件标题,开始日期,结束日期和位置。
html代码: encodeURIComponent(txt1 + "\n" + txt2 + "\n" + txt3 + "\n" + txt4)

以及如何将这些值放入此代码中:

@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);
    }
}

1 个答案:

答案 0 :(得分:1)

您可以使用String.split()将字符串分成子字符串。这将为您提供可以传递给意图的字符串数组。

        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);