如何从qr扫描中获取两个不同的结果

时间:2016-08-30 07:24:44

标签: java android

所以我需要获取结果,当我使用登录按钮扫描时,当我使用注销按钮扫描时,另一个结果。这是因为他们应该更新2个不同的表(signIn和sigOut表)

 try {
        Button scanner = (Button)findViewById(R.id.signInBtn);
        scanner.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                intent.putExtra("SCAN_MODE", "QR_CODE_MODE");

                startActivityForResult(intent, 0);

            }

        });

        Button scanner2 = (Button)findViewById(R.id.signoutBtn);
        scanner2.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                Intent intent1 = new Intent("com.google.zxing.client.android.SCAN");
                intent1.putExtra("SCAN_MODE", "QR_CODE_MODE");
                startActivityForResult(intent1, 0);
            }

        });

    } catch (ActivityNotFoundException anfe) {
        Log.e("onCreate", "Scanner Not Found", anfe);
        getClass();
    }

    list= (Button) findViewById(R.id.lookup_btn);
    list.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v){

            Intent intent = new Intent(MainActivity.this,SearchActivity.class);
            startActivity(intent);
            finish();
        }
    });

}

1 个答案:

答案 0 :(得分:0)

只需在代码中更改这两行

即可
 startActivityForResult(intent, 0);

 startActivityForResult(intent1, 1);

并根据结果

对onActivityResult进行更改