how to get qr scaning result as a int or string android studio java

Viewed 62

hi im new at android studio. i write a code to scan qr code and its work clear but i just want to use the result to act on like if result is 1316 i wanna get it like integer and use like (if (result%==2) bla bla) or (result.charAt(2)) how can i do it? thx for help

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btScan = findViewById(R.id.bt_scan);
    btScan.setOnClickListener(new View.OnClickListener() {

        @Override

        public void onClick(View view) {
            IntentIntegrator intentIntegrator = new IntentIntegrator(
                    MainActivity.this

            );
            intentIntegrator.setPrompt("For flash use volue up key");
            intentIntegrator.setBeepEnabled(true);
            intentIntegrator.setOrientationLocked(true);
            intentIntegrator.setCaptureActivity(Capture.class);
            intentIntegrator.initiateScan();
        }
    });
    
    
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    IntentResult intentResult= IntentIntegrator.parseActivityResult(
            requestCode,resultCode,data
    );
    if (intentResult.getContents() != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                MainActivity.this
        );
        builder.setTitle("Result");
       // builder.setMessage(intentResult.getContents());

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
            }
        });
        builder.show();

    }else {
        Toast.makeText(getApplicationContext()
        ,"OOPS... You did not scan anything",Toast.LENGTH_SHORT).show();
    }
}

}

0 Answers
Related