Launch application on click of specific url - android

When any video url is clicked, on the android phone, I want my application to be displayed in popUp, which says, do you want to play the link using, chrome, or myApp..
I want this to happen only for specific Video links, like Youtube video URLs only. In short my application will work as an browser only for specific video links.
How should I achieve this.

Look into Intent Filters. You can use them to register your app to handle certain file types or specific url schemes.

<activity android:name=".YourActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data android:scheme="http" android:host="www.youtube.com" ></data>
</intent-filter>
</activity>
You might also want to use the same scheme for https and mobile, do not forget it ;-)
<data android:host="www.youtube.com" android:scheme="http" />
<data android:host="www.youtube.com" android:scheme="https" />
<data android:host="m.youtube.com" android:scheme="http" />
<data android:host="m.youtube.com" android:scheme="https" />

Related

Android-How to open my app from the browser

I am developing a parental control app, the goal is, when certain websites are accessed, my app would pop up.
From my research, the way to accomplish this is by adding intent-filter to AndroidManifest.xml
For now my activity looks like this
<activity
android:name=".BlockActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
From my understanding, this should intercept any website access because I did not specify any host in data attributes. However, when I open, say, www.google.com, my activity does not start.
I also tried specifying the host like this, but it also did not work.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:host="www.google.com"/>
<data android:pathPrefix="/"/>
<data android:mimeType="*/*" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
Out of curiosity, I tried another intent-filter with android.intent.action.SEND, and it does trigger for sharing.
FYI, I am testing on a virtual device with API Level 30.
Any insights on my goal of intercepting web browsing are welcome, at this stage I am not even sure if intent-filter is the right way to do it.
I later figured out that the better way of implementing what I'm trying to accomplish is to use AccessibilityService.

Android Deep Linking without android:scheme

I have a activity that apply intent filter to open deeplink, this is my intent filter :
<intent-filter android:autoVerify="true">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPattern="/..*"
android:scheme="https" />
</intent-filter>
my problem is, when user open a link i.e "www.example.com/somepage" from messaging apps e.g Hangout,Whatsapp, Android app chooser doesn't display may apps in its list, it just show all browser app in the options. But when user put "https://www.example.com/somepage" in a message then it works, Android show my app in its App chooser to open the link.
It also doesn't work When I try to remove android:scheme="https" from my intent filter.
is there anyone has same problem and have a solution?
Any help really appreciated.
This is expected behavior.
What the following snippet does is register your app as a handler for the URL scheme https://
<data
android:host="www.example.com"
android:pathPattern="/..*"
android:scheme="https" />
This means your app will be offered as an option for any link beginning with https:// and containing www.example.com. The string www.example.com/somepage doesn't qualify, as it is missing the https:// part.
You could try adding a second filter for http:// links. I'm not sure if Android automatically infers that as the scheme for web links without a scheme specified, so it's possible this could resolve the issue.
<intent-filter android:autoVerify="true">
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPattern="/..*"
android:scheme="https" />
<data
android:host="www.example.com"
android:pathPattern="/..*"
android:scheme="http" />
</intent-filter>

Android: app linking - supporting only certain paths?

I want to setup app linking for my app but only for it to be active on certain paths. In other words, in my manifest:
<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.mydomain.com/[mypath]" />
<data android:scheme="https" android:host="www.mydomain.com/[mypath]" />
</intent-filter>
I don't want every url that has my domain to open the app - they can open in the browser as usual. I only want urls that include the specific subpath to open in the app. Is this pattern allowed or is it "all or nothing" for app linking?
Link to the developer docs:
http://developer.android.com/training/app-links/index.html
You can have special paths, but you can't/shouldn't have them appended to the host.
You should have
<data android:scheme="https" android:host="www.mydomain.com" />
And from there you can use the android:path android:pathPattern or android:pathPrefix to create special patterns.
For example,
<data android:scheme="https" android:host="www.google.com" android:path="/en/index.html"/>
would only catch the url "https://www.google.com/en/index.html"

Android respond only to a Sub-URI

My App is able to respond to any link in the browser visiting example.com with the following code. My question is, how can I program my app only to respond to
"http://example.com/#push/...".
I have to implement it this way, because only if the link contains the specific path, it should be possible to open the link with my app. Not in general. Another possible solution would be to allow any URI, but that one. So my App respond to any link but one.
<intent-filter>
<data
android:host="example.com"
android:scheme="http" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
</intent-filter>
I tried to add a pathPattern, but that results in not opening the link anymore:
<data
android:host="example.com"
android:pathPattern=".*push.*"
android:scheme="http" />
You should try with
<data
android:host="example.com"
android:pathPrefix="/#push/"
android:scheme="http" />
This way you can check only the initial part of the path.
Remember to include the leading / since it is a path segment.
The official documentation has a couple of examples on using the element:
http://developer.android.com/guide/topics/manifest/data-element.html

redirect app when open custom url in browser android

How to make redirect my app without dialog (Choose Option) when user open custom url like this
https://signin.ebay.com/ws/eBayISAPI.dll?ThirdPartyAuthSuccessFailure&isAuthSeccesfull=true&ebaytkn=&tknexp=1233-4503223
I've tried to using intent filter in my android manifest like this
<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="signin.ebay.com" android:pathPattern="/ws/eBayISAPI.dll?/ThirdPartyAuthSuccessFailure&isAuthSuccessful=true*"/>
<data
android:scheme="http"
android:host="signin.ebay.com" android:pathPattern="/ws/eBayISAPI.dll?/ThirdPartyAuthSuccessFailure&isAuthSuccessful=true*"/>
</intent-filter>
but its not working , but when I've tried code like this
<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="signin.ebay.com" />
<data
android:scheme="http"
android:host="signin.ebay.com"/>
</intent-filter>
its working but it show dialog ChooseOption sometimes I open browser with url https://signin.ebay.com or http://signin.ebay.com
How to make when user open url this
https://signin.ebay.com/ws/eBayISAPI.dll?ThirdPartyAuthSuccessFailure&isAuthSeccesfull=true&ebaytkn=&tknexp=1233-4503223
they will redirect to my app WITHOUT dialog box ChooseOption , my tknexp is not static remember , thanks
It is asking to choose option because you have given android:scheme="https". Because of this Android will look for applications , which supports android:scheme="https" and will show user if there are multiple application taking care of thie scheme.
To Avoid it change the android:scheme="https" to android:scheme="<your own scheme>" which is handled by only you app. This will redirect directly to you application.
Now in your activities onCreate method you will receive the URL with instead of https://. But now you have total control on url , you can change it to https://.

Categories

Resources