start activity from browser - android

Im trying to register a protocol in my app whereby a url executed in the android browser will launch my activity, all the examples Ive seen on the web say to add an Intent Filter on my activity such as
<activity android:name=".UrlActivity">
<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" android:host="myhost"/>
</intent-filter>
</activity>`
but this doesnt seem to be enough to get the Android OS to launch my activity...
Is there anyone who could tell me if there is something Im missing?
Thanks

Try removing theandroid:host part, but retain the android:scheme attribute.
Also check logcat for any errors or warnings.

The URL has to be made available as a hyperlink on a page for the user to tap. Entering the URL in a browser on your device will not work. This resolved the problem for me.

Related

Handling external links in android webview

I want to open my app and load the URL when specific links are clicked.
This is my Manifest for handling external links.
<intent-filter android:autoVerify="true">
<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="www.android.com" />
<data android:scheme="https" android:host="www.android.com" />
</intent-filter>
And for handling incoming links this is the code
intentData = getIntent().getData();
if(intentData !=null){
loadUrl = intentData.toString();
}else {
loadUrl = "https://www.android.com";
}
webView.loadUrl(loadUrl);
Now when I clicked https://www.android.com from external app like whatsapp its loaded in webview but the webview is attached to whatsapp. Check screenshots below.
And if anyone can give me any hints or guide me on how to open my app when I open the URL(https://www.android.com) from Google Chrome(in my phone) will be a great help
For second part of your question:
And if anyone can give me any hints or guide me on how to open my app
when I open the URL(https://www.android.com) from Google Chrome(in my
phone) will be a great help
take a look at this answer:
"Essentially, the Chrome team feels that if a user actually types something into the address bar, no redirect should ever happen. As you've discovered, this is counter to behavior in all other browsers."
Use this line in Manifest file of your Activity which is Handling that intent to avoid such problem.
android:launchMode="singleTask"
You can find detail implementation here, https://developer.android.com/guide/webapps/webview.html
You have to override methods, and handle clicks.

Intent-filter - Open NEW application, not embedded one

I don't know if it's really understandable.
When i'm clicking on a llink in a mail, I can open this link with my application and that's perfeclty what I want.
<intent-filter>
<data android:scheme="https" android:host="xxx.xxx.com"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
BUT
When i'm opening my application like that, and I check the opened application, I see that my application is "inside" Gmail task, like that
But, when i'm opening the link with Chrome for exemple, Chrome is opening in his own task, like that
How can my application open in her own task and NOT inside Gmail's one ?
you have to set a specific andorid:launchMode to your activity:
android:launchMode="singleTask"
or
android:launchMode="singleInstance"
placed in the declaration of your activity in the AndroidManifest.xml will do it.
take a look also at this article that explain how android handles tasks and activities

How to use IntentFliter for URL to get every link?

I am trying to set up a filter for URLs specific to my domain and a certain subdomain. This is what I have so far:
<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="https" android:host="www.mywebsite.com" android:pathPattern="/mysubdir/id=*"/>
</intent-filter>
I tried it without the host (only pathPattern), with and without the first slash on pathPattern and every combination I thought of, but it always links my app to every https link I click. What is going on here?
Thanks in advance.
EDIT:
I realised that I should be using pathPattern=/mysubdir/id=.* , but even after this change, nothing happens.

Android Intent launch from browser

This topic has been covered before, but I can't find an answer specific to what I'm asking.
Where I am: I followed hackmod's first piece of advice here: Make a link in the Android browser start up my app? and got this to work with a link in the webpage.
However, I'm having trouble understanding the second option (intent uri's). here's what I've got:
<activity android:name="com.myapps.tests.Layout2"
android:label="Auth Complete"
>
<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="mydomain.com"
android:path="/launch" />
</intent-filter>
</activity>
Now, with that I can go to "mydomain.com/launch" and it launches my activity. this all works well, except that I get the chooser. what I want is for it to just launch my activity without giving options.
From the explanation in the post I referenced it looks like thats what intent uris are for,but I can't find a straightforward example. what should my link in my webpage look like in order to launch this with no chooser?
I've seen a couple of examples that look something like this:
<a href="intent:#Intent;action=com.myapp.android.MY_ACTION;end">
However, that doesn't seem to work when I try it.
My test device is a Galaxy Tab 2.
any help would be appreciated.
I was also trying to launch the app in the recomended way. The following code worked for me.
Code inside the <activity> block of YourActivity in AndroidManifest.xml :
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="your.activity.namespace.CUSTOMACTION" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Code in the activities onCreate() method :
Intent intent = getIntent();
if(intent != null && intent.getAction() == "your.activity.namespace.CUSTOMACTION") {
extraValue = intent.getStringExtra("extraValueName");
Log.e("AwseomeApp", "Extra value Recieved from intent : " + extraValue);
}
For the code in HTML, write an intent for launching the specific Activity, with the action your.activity.namespace.CUSTOMACTION, and your application package name your.activity.namespace. Your can also put some extra in the intent. For example intent.putExtra("extraValueName", "WOW"). Then get the required URL by printing the value of intent.toUri(Intent.URI_INTENT_SCHEME) in the Log. It should look like :
intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end
So your HTML code should look like :
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.activity.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
This is as per what #hackbod suggested in here and this page from developers.google.com.
Depending on your intent filter this link should work:
start my app
But you should note that the android system will ask the user if your app or any other browser should be started.
If you want to avoid this implement a custom protcol handler. So just your app will listen for that and the user won't get the intent chooser.
Try to add this data intent:
<data android:scheme="mycoolapp" android:host="launch" />
With the code above this link should work:
start my app
I needed a small change to abhishek89m'a answer to make this work.
<a href="intent:#Intent;action=your.example.namespace.CUSTOMACTION;package=your.example.namespace;component=your.example.namespace/.YourActivity;S.extraValueName=WOW;end">
Launch App
</a>
I removed ".activity" after the slash in component name.
And I want to add, that custom action is probably the best answer to this problem if you don't want the app chooser to show up.
p.s. I would add this as comment, but I'm a new user and I don't have enough reputation points.
<a href="your.app.scheme://other/parameters/here">
This link on your browser will launch the app with the specific schema
like that on your intent
<intent-filter>
<data android:scheme="your.app.scheme" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>

Android: open Activity from URL show instead of calling app in recent apps

I have an IntentFilter set in my Activity like:
<intent-filter>
<data android:host="www.example.com" android:scheme="http" android:pathPrefix="/d/"/>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>
its working great to launch the Activity when a link is pressed, the problem is that looking in recent apps, my Activity shows in the preview of the calling app, instead of having its own instance.
for example: if a link with the url is clicked from WhatsApp, in recent apps I see my Activity in the preview for WhatsApp, instead of seeing my app opened in addition to WhatsApp.
I checked other apps and none of them is acting like that.
how do I fix this ?

Categories

Resources