Pages

Wednesday, March 9, 2011

QR-code to launch your app

Android intents are powerful, you can even set you application to launch on a certain URL.

Launch app on defined URL

To make your app launch on a specific URL you simply create an intent filter.

<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="http" android:host="xebralabs.blogspot.com" android:path="/travalert"/>
</intent-filter>

This way you can have your application launched from a QR-code containing the specific URL. Nice thing is that if the app isn't installed the user will most likely have the url opened in a browser instead.

4 comments:

  1. Hi, could you clarify what should be the url which will be used to launch that app, because I've tried few urls but always a browser has been opened

    ReplyDelete
  2. I managed to get it :). If someone complete example, let's take a look here: http://stackoverflow.com/questions/7416864/about-starting-android-app-from-an-url.

    in the comments below there is example project.

    ReplyDelete
  3. Glad to hear you solved it. Maybe I was a bit vague on the details ;)

    ReplyDelete
  4. String contents = intent.getStringExtra("SCAN_RESULT");
    String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
    // Handle successful scan
    } else if (resultCode == RESULT_CANCELED) {
    // Handle cancel
    }
    }jkioiuiozui

    ReplyDelete