Starting an application from the Lollipop browser - HOW TO?

Regardless of the below approach - I.e. Method A or Method B - used to launch my application, the Lollipop browser inevitably raises a net::ERR_UNKWON_URL_SCHEME error

Note: such difficulty is not observed while using the KitKat Browser.

 

HTML page used to launch my app

<a href="myscheme://">Method A</a>

<a href="intent:/#Intent;scheme=myscheme;package=com.zebra.bqmk34.spr31005;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;end">Method B</a>

 

 

AndroidManifest.xml MainActivity.java
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   
package="com.zebra.bqmk34.spr31005">

    <
application
       
android:allowBackup="true"
       
android:icon="@mipmap/ic_launcher"
       
android:label="@string/app_name"
       
android:supportsRtl="true"
       
android:theme="@style/AppTheme">
        <
activity
           
android:name=".MainActivity"
           
android:label="@string/app_name"
           
android:theme="@style/AppTheme.NoActionBar">
            <
intent-filter>
                <
action android:name="android.intent.action.MAIN" />

                <
category android:name="android.intent.category.LAUNCHER" />
            </
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="myscheme" />
            </
intent-filter>

        </activity>
    </
application>
</
manifest>
@Override
protected void onCreate(Bundle savedInstanceState) {
   
super.onCreate(savedInstanceState);
    setContentView(R.layout.
activity_main);

   
txtInfo = (TextView)findViewById(R.id.txtInfo);
    Intent intent = getIntent();
   
if (intent != null){
        String strAction = intent.getAction();
        Log.d(
TAG, "Intent action = " + strAction);
        Uri launchUriPassedIn = intent.getData();
       
if (launchUriPassedIn != null) {
           
txtInfo.setText(launchUriPassedIn.toString());
            Log.d(
TAG, "URI = " + launchUriPassedIn.toString());
            String strQuery = launchUriPassedIn.getQuery();
            Log.d(
TAG, "URI Query = " + strQuery);
        }
       
else {
           
txtInfo.setText("No intent data found!");
            Log.d(
TAG, "No intent data found!");
        }
    }
   
else {
       
txtInfo.setText("No intent found!");
        Log.d(
TAG, "No intent found!");
    }
}

 

Any hint is welcome!

Thank you.

Anonymous (not verified)
For method B, you only have

For method B, you only have one forward slash in the URL scheme, is that just a typo in the question?

<a href="intent:/#Intent;

You also need to export the activity from the manifest according to this StackOverflow post: Launch android application from a browser link - Stack Overflow 

Another possibility is a difference between your KitKat and Lollipop devices.  The documentation I can see online says this works in Chrome but I am unsure if this would work in the standard Android webview available on non-GMS devices, perhaps one of your devices has Chrome as the underlying renderer and the other does not.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jacques Gourmelen
Thanks for the prompt reply

Thanks for the prompt reply Darryn.

Right you are, I made a typo.

Method B href attribute must indeed start with two forward slashes <a href="intent://#Intent; [...] ;end">.

Exporting the activity - I.e. adding android:exported="true" to the activity in the AndroidManifest.xml file - does not seem to make a difference from my end.

Note: I am currently conducting my tests against the same MC18 unit onto which KitKat or Lollipop is loaded

MC18 KitKat Chrome User Agent String
MC18 KK - system info.png MC18 KK - User Agent info.png
MC18 Lollipop Chrome User Agent String
MC18 L - system info.png MC18 L - User Agent info.png
Method A or B.html Result

Selecting Method B (*)

device-2017-02-03-115949.png

inevitably raises the following error:

device-2017-02-03-115958.png

(*) source reads

<a href="intent://#Intent;scheme=myscheme;package=com.zebra.bqmk34.spr31005;action=android.intent.action.VIEW;category=android.intent.category.DEFAULT;category=android.intent.category.BROWSABLE;end">Method B</a>

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
I only have an MC40 to test

I only have an MC40 to test with I'm afraid as I have no access to an MC18.

It works well for me with Lollipop on MC40 but I am able to reproduce your error if I load the HTML page directly from device storage.  Are you loading your HTML page from an HTTP server?  The error could be a result of trying to run cross origin

Edit: I mean it could go against Chrome's content security policy (Content Security Policy (CSP) - Google Chrome ), this might also explain why it worked with KitKat as perhaps the security policy was not implemented there.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jacques Gourmelen
I am indeed opening the

I am indeed opening the Method A or B.html page locally.

This html file sits on the device /sdcard folder.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
That is the problem then, the

That is the problem then, the file cannot be run directly from the local file system it would seem but only works from a server.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jacques Gourmelen
Thanks Darryl. I do confirm

Thanks Darryl. I do confirm your findings / observations:

If the HTML file used to launch the application sits on server, then no net::ERR_UNKWON_URL_SCHEME error gets raised.

Any ideas how we could alleviate this issue?

I spent most of the day searching for a solution but must admit I could find one.

Thanks in advance.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
You could try hosting the

You could try hosting the file(s) through a local web server on the Android device, there are quite a few apps that should allow that but obviously the MC18 is AOSP.

A Google search didn't bring up much but searching github I see GitHub - lopspower/AndroidWebServer: Android Web Server (NanoHttpd) , that looks promising and is released under Apache.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Jacques Gourmelen
Hum... it might indeed be

Hum... it might indeed be promising but why do I have the unpleasant feeling that we are trying to kill a fly with a cannon.

Indeed, my understanding is the following: the inquirer simply wishes to launch the execution of an application using a hyperlink from a local HTML page.
Such approach works under KitKat but not under Lollipop.

This said, I will see if the inquirer is amicable to hosting the file(s) through a local web server on the Android device.

Thanks for all your help Darryn.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments