Scan QR Code To Open Specific Content In An Android App

Scan QR Code To Open Specific Content In An App

Introduction

This blog discusses the approach and solution to open specific content in an app by scanning a QR code. The following examples give use cases of opening specific content in the app

Example 01:

There is a science text book and the same publisher also has an android app that has all the related information and much more. In a particular chapter of the book, there is a QR code. When this QR code is scanned, it should open the app and take the user to the related chapter content on the app.

Example 02:

An app vendor has a website to promote the app. In the google search results, when someone searches for a relevant keyword and comes to the website, easy access has to be given to the relevant content in the app. The use case can be that  the user clicks on a link in the mobile or scans a QR code on the website and has to be taken to some specific page in the app.

We can make use of the firebase dynamic links feature to achieve this.

With Dynamic Links, you can seamlessly transition users from your mobile website to the equivalent content within your app. And because the links survive the app install process, even new users can pick up where they left off on your mobile site without missing a beat.

Process Roadmap Diagram Infographic Graph 1

Deep Links

Deep links let you redirect users to a specific destination inside your app which provides a better user experience.

A deep link is a URL that navigates to a specific destination in your app. When you click a deep link, Android:

  • Opens the user’s preferred app that can handle the link, if it’s available.
  • If the preferred app isn’t available, it opens the only app that can handle the link.
  • If multiple apps can handle the link, it opens a dialog that lets the user select from one of the apps that can open the link.
  • If the app is not installed it redirects to the app in the playstore.

Consider the deep link https://www.aksharaontech.com/test/code=abcd. It has the following parts:

  • https: Identifies the protocol used to access the resource on the internet.
  • www.aksharaontech.com: The host, which is the name or address of the web server being accessed.
  • test: The path which specifies a particular page of content.
  • code: The query parameter you can extract from intents in your destination. abcd is the value of the parameter.

To add deep link & use of this feature we have to add dynamic link support to the app.

You may want to check out the blog link below  to add dynamic link support to the app and the setup process.

If you are done with setup, add intent filters in the android manifest file.

Add an intent filter for deep links

you must add a new intent filter to the activity that handles deep links for your app.

<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:host=”example.com”
     android:scheme=”https”/>
</intent-filter>

The intent filter is required for your app to receive the Dynamic Link data after it is installed/updated from the Play Store and one taps on the Continue button. The intent filter catches deep links of your domain, since the Dynamic Link will redirect to your domain if your app is installed.

When users open a Dynamic Link with a deep link to the scheme and host you specify, your app will start the activity with this intent filter to handle the link.

Handle deep links

To receive the deep link, call the getDynamicLink() method:

FirebaseDynamicLinks.getInstance()
    .getDynamicLink(getIntent())
    .addOnSuccessListener(this, new OnSuccessListener() {
      @Override
      public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
        // Get deep link from result (may be null if no link is found)
       Uri deepLink = null;
       if (pendingDynamicLinkData != null) {
         deepLink = pendingDynamicLinkData.getLink();
       }
      // Handle the deep link. For example, open the linked
      // content.
      }
})
.addOnFailureListener(this, new OnFailureListener() {
  @Override
  public void onFailure(@NonNull Exception e) {
    Log.w(TAG, “getDynamicLink:onFailure”, e);
  }
});

You must call getDynamicLink() in every activity that might be launched by the link, even though the link might be available from the intent using getIntent().getData(). Calling getDynamicLink() retrieves the link and clears that data so it is only processed once by your app.

You normally call getDynamicLink() in the main activity as well as any activities launched by intent filters that match the link.

Here in the above deep link url we are passing host and required parameters separated with ampersand to access a particular content directly without being following the normal app flow.

We will parse the host-aksharaontech.com and different parameters which we can use to do appropriate action(In this case we can use courseid, chapterid, subchapterid, contenttype and contentid and open the particular content on the launch of the app) inside the app.

After accessing the deep link URL(created earlier while creating dynamic links using firebase console) on launch of app you can parse the URL so you can get your required parameters from it and can use your own execution to open the linked content.

This solution is based on firebase dynamic links feature and can be used in multiple user scenarios and cases. The capability to open specific content in the app improves the user experience in terms of improved efficiency to reach the desired content. In Techpearl, we got enhanced user experience results and better customer satisfaction by applying the above solution.

Read More Articles

 Contact Us Now

Talk to us to find out about our flexible engagement models.

Get In Touch With Us