0rka
0rka

Reputation: 2386

Is it possible to add extras to browsable intents from HTML

Let's take per say the following manifest:

<intent-filter>
    <data scheme="myscheme"
          host="myhost">
    </data>
    <action name="android.intent.action.VIEW">
    </action>
    <category name="android.intent.category.DEFAULT">
    </category>
    <category name="android.intent.category.BROWSABLE">
    </category>
</intent-filter>

I could launch the activity which under the above intent filter is declared by redirecting the browser to:

myscheme://myhost?param1=param1&param2=param2

However, I'm struggling with understanding if it is possible to do the same redirection, only with additional extras that would be received programmatically with:

myextra = getIntent().getStringExtra('myextra')

Any help would be very much appreciated.

Upvotes: 2

Views: 2367

Answers (3)

0rka
0rka

Reputation: 2386

One could use "intent scheme URL" in order to send more information like extra objects and actions when redirecting to a custom intent scheme URL via javascript or HTML.

intent://foobar/#Intent;action=myaction1;type=text/plain;S.xyz=123;end

Although this method doesn't actually answer the question as the scheme part is destined to always be "intent", this is a possible way to send intents from browsers with extra object or actions.

See more extensive information in the following report:

http://www.mbsd.jp/Whitepaper/IntentScheme.pdf

Or use the chrome documentation:

https://developer.chrome.com/multidevice/android/intents

Upvotes: 2

kenny_k
kenny_k

Reputation: 3990

The only ways to pass data directly from a web page to your app is on the URL that you register in an intent-filter. All to be retrieved via the Uri object - whether the data is on the path or with query params, as outlined below. There is no way to set extras on an Intent from a web page.

Uri uri = getIntent().getData();
String param1Value = uri.getQueryParameter("param1");

Upvotes: 1

Berkay92
Berkay92

Reputation: 586

This is how I overcome this issue,

I developed my own browser and made browsable like you do

Uri data = getIntent().getData();

if(data == null) { // Opened with app icon click (without link redirect)
    Toast.makeText(this, "data is null", Toast.LENGTH_LONG).show();
}
else { // Opened when a link clicked (with browsable)
    Toast.makeText(this, "data is not null", Toast.LENGTH_LONG).show();
    String scheme = data.getScheme(); // "http"
    String host = data.getHost(); // "twitter.com"
    String link = getActualUrl(host);
    webView.loadUrl(link);
    Toast.makeText(this,"scheme is : "+scheme+" and host is : "+host+ " ",Toast.LENGTH_LONG).show();
}

I think you are looking for this functions

data.getQueryParameter(String key);

Upvotes: 1

Related Questions