比较qrcode值和文件项

时间:2019-01-05 19:00:02

标签: android string compare barcode

我正在尝试将条形码值与实际上从文件读取的字符串进行比较,如果值相等,我举杯祝酒,说票证正确,否则吐司说了错误的票证。有人可以帮我吗,我是使用google API视觉扫描条形码(qrcode)

final SparseArray<Barcode> qrcode = detections.getDetectedItems();
                if (qrcode.size() != 0) {
                    textView.post(new Runnable() {
                        @Override
                        public void run() {
                            textView.setText(qrcode.valueAt(0).displayValue);
                            int i=0;
                            StringBuffer sb=new StringBuffer();
                            String ti=qrcode.valueAt(0).toString();
                            String dat =null;
                            InputStream is = getApplicationContext().getResources().openRawResource(R.raw.fichier);
                            BufferedReader read = new BufferedReader(new InputStreamReader(is));
                            if (is != null) {

                                try {
                                    while ((!trouve) && (dat = read.readLine()) != null) {
                          // sb.append(dat); I DONT REALLY USE THIS LINE

                                        if (ti.equals(dat))
                                            trouve = true;
                                        i++;

                                    }
                                    if (trouve) {
                                        Toast.makeText(MainActivity.this, "Validé Bonne soirée[" + String.valueOf(i) + "]", Toast.LENGTH_LONG).show();

                                    }
                                    else
                                        Toast.makeText(MainActivity.this, "Veuillez acheter un bon ticket celui ci n'est pas valide[" + String.valueOf(i) + "]", Toast.LENGTH_LONG).show();

                                }

0 个答案:

没有答案