-1

I made a QR reader APP for my school project, the app works very well but it has a little mistake. When I scan a QR code the app just shows me the text. However, when I created a QR code linked to "www.google.com" (a simple link), my app just shows me "www.google.com" and doesn't open it in the browser.

I use this video to make my app : https://youtu.be/Fe7F4Jx7rwo He is a nice guy He said : "use intent to open it in a browser"

But as I said in previous posts : "in my school my teacher prefer to teach Visual Basic instead Java or C++" ... So I'm a 0 in Java or C++

Can anyone suggest what to do?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • 1
    Can you post your code so we can suggest modifications? This question may help you http://stackoverflow.com/questions/2201917/how-can-i-open-a-url-in-androids-web-browser-from-my-application – Juan Martinez Feb 21 '17 at 14:59

1 Answers1

0

I suggest the following. When you get the text from the QR call the following code to either open the browser or show the text on the screen (your current implementation):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    ...
    String text = resultCode.getContents();
    if (Patterns.WEB_URL.matcher(text).matches()) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(text));
        startActivity(browserIntent);
    } else {
        Toast.makeText(this, text, Toast.LENGTH_LONG).show();
    }
}
Doron Yakovlev Golani
  • 5,188
  • 9
  • 36
  • 60
  • Like this Doron ? : https://gyazo.com/10398916d32a51ebcdecaf90a6c13e28 As I said , I don't know about JAVA ou Android Studio. If you help me I will pay you a coffee I PROMISE !! – Diogo Calisto Feb 21 '17 at 15:56
  • Considering your code, it should be something like this. No need to buy me anything :D You can approve the answer and up vote it if it helps you. – Doron Yakovlev Golani Feb 21 '17 at 16:08
  • Thanks Doron I will give you feedback !! – Diogo Calisto Feb 21 '17 at 16:19
  • Hi again Doron. I'm working again on my project and I developed a little bit more but I have some questions. How I can converter the "result" (which I receive from QR code) in link to paste "URI.parse" ? because when I scan my smartphone always show google but what I want is my smartphone showing the URL that I create in my QR CODE. The code : https://shrib.com/see/xsYZKXnUos3I7EPhYujHJR4j9270dlpQTDqeaTyFBrN9wdhKNG?v=nc – Diogo Calisto Feb 23 '17 at 16:59
  • I made a small mistake in the code - it should have been `Uri.parse(text)` and not `Uri.parse("http://www.google.com")` – Doron Yakovlev Golani Feb 23 '17 at 18:02
  • Thank you Doron ! Other mistake that I did is when I create the QR code I just write "www.blablabal.com" and I need to put "https://www.blablablabl.com" – Diogo Calisto Feb 24 '17 at 13:23