I'm trying to build an app for learning purposes. It's a simple QR code and Barcode scanner app with a two flows:
- If the pattern of the scan is an URL open the browser
- If the pattern is not an URL open the browser with google.com/+string from the scan.
I have achieved goal number one with the if statement
public void handleResult(Result result) {
final String myResult = result.getText();
Log.d("QRCodeScanner", result.getText());
Log.d("QRCodeScanner", result.getBarcodeFormat().toString());
if(Patterns.WEB_URL.matcher(result.getText()).matches()) {
// Open URL
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(result.getText()));
startActivity(browserIntent);
}
}
My challenge is now with goal number to which I just can't get to compile. I was thinking using an else statement and parse Uri with something like google.com + the string. The expected result is that if the scanner returns and value which is not a URL pattern open the browser go to google and search with the return value.
I hope I make myself clear. Pretty much a newbie here - trying to learn terminology and way to communicate.
Aucun commentaire:
Enregistrer un commentaire