Doubt with the Toast in response to Zxing code QR

0

I want to know if there is any way to get the message displayed in the Toast in a different way.

I have created a QR code reader that works with zxing. When scanning the code, the result is sent to a toast. I want the message that results from the QR code to be displayed in another window and if it is a link that allows me to open it with the default browser of my mobile phone.

public class MainActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{
    private ZXingScannerView zXingScannerView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void scan(View view){
        zXingScannerView =new ZXingScannerView(getApplicationContext());
        setContentView(zXingScannerView);
        zXingScannerView.setResultHandler(this);
        zXingScannerView.startCamera();

    }

    @Override
    protected void onPause() {
        super.onPause();
        zXingScannerView.stopCamera();
    }

    @Override
    public void handleResult(Result result) {
        Toast.makeText(getApplicationContext(),result.getText(),Toast.LENGTH_LONG).show();
        zXingScannerView.resumeCameraPreview(this);

    }
}
    
asked by Luna Va 25.08.2017 в 03:58
source

1 answer

0

I guess what you get from the QR is simple text, I suggest the following:

try{
   URL url = Uri.parse(stringRespuesta));
   Intent browserIntent = new Intent(Intent.ACTION_VIEW, url);
   startActivity(browserIntent);
catch(Exception e){
  //La respuesta no es una url
  Intent intent = new Intent(this, OtraActividad.class);
  intent.putExtra("respuesta", stringRespuesta);
  startActivity(intent);
}

Automatically intent of the url will open the determined browser and if it is not an url then it will send you to another activity where you can receive the answer in this way:

Bundle bundle = getIntent().getExtras();
String respuesta = bundle.getString("respuesta");

Good luck!

    
answered by 25.08.2017 / 05:10
source