I've placed a deep link in my manifest using (I think) the format from the documentation
<activity
android:name="my.package.name.AInviteFriends"
android:label="#string/title_activity_a_invite_friends"
android:launchMode="singleTask"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter android:label="#string/filter_view_invite_friends">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="my.package.name" /custom scheme I was told to use
android:host="companyurl.com"
android:pathPrefix="/invite_friends"
/>
</intent-filter>
</activity>
I then navigate to this URL from within the app, hoping for it to be intercepted and go to the activity. I'm not sure why we're using deep links instead of a normal intent, I think it's for tracking or something:
my.package.name://company.com/invite_friends
But when I try this, the browser opens with a Webpage not available/ERR_UNKNOWN_URL_SCHEME error. What am I missing about this intent?
I am not sure you can use an 'address-like' scheme.
I would start with a simple scheme, e.g 'mygreatapp' (the URI is mygreatapp://) and no host or pathPrefix.
See how it works for you and go from there
Related
I seem to be doing something wrong with deep linking in my app. I have two activities: a post viewer which views posts on a site, and a profile viewer which views a users profile. Below is my code that I've set up following Google's guide to deep linking.
Profile Activity Manifest Declaration
<activity
android:name=".ui.activity.ProfileActivity"
android:parentActivityName=".ui.activity.MainActivity">
<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="gab.ai"
android:pathPattern="/..*"
android:scheme="https" />
</intent-filter>
</activity>
Post Viewer Activity Manifest Declaration
<activity
android:name=".ui.activity.PostViewerActivity"
android:parentActivityName=".ui.activity.MainActivity">
<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="gab.ai"
android:pathPattern="/..*/posts/..*"
android:scheme="https" />
</intent-filter>
</activity>
I've left out the intent handling code because it is redundant. The deep links work properly, except for a weird issue when opening URLs that direct to the post viewer activity.
This works perfectly. Tapping a link such as https://url/.. opens the dialog and lists only one option When selecting the app, it opens the proper activity perfectly.
Here's where it gets weird. When clicking a URL such as https://url/../posts/.. the Android System sees both activity deep links as feasible. My question is how do I get around this? Changing the URL scheme is out, and I'm not fluent enough about deep links to figure out a workaround.
In ProfileActivity android:pathPattern="/..*" equals to /..*/posts/..* because an asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character. Try to use escape character \ as explained in docs
There is a perfect way to launch our android application through Deeplink.
<activity
android:name="com.example.android.GizmosActivity"
android:label="#string/title_gizmos" >
<intent-filter android:label="#string/filter_title_viewgizmos">
<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.example.com"
android:pathPrefix="/gizmos" />
</intent-filter>
</activity>
Here, I can easily launch my application through “http://www.example.com/gizmos”, But my question comes when I am going to hit shorten URL of this link i.e. goo.gl/tNQpWe.
What could be the ways to launch my app through tiny/ shorten url too ?
Please suggest.
The short url will be redirecting to your server/domain and from there you do the same what "gizmos" did. Deep linking is basically a HTML page rendering some expected data by your android application (In your case android:host and android:pathPrefix)
You will need to create a basic html rendering the android schema if you need data to be passed. I would suggest you to follow Branch.io.
https://blog.branch.io/technical-guide-to-deep-linking-on-android-chrome-intents
I've been trying to use deep linking from a website I own to a resource inside my app. I've been reading about how things has evolved with deep linking in Android, particularly Paul Kinlan's blog post which seems to be the most recent explanation on how things should work.
I also have read this discussion on why custom scheme is a bad practice and should not be used, which made sense.
Now I decided to use the #intent link in my website to open the resource in the app when user taps on the link. For this, I used a link like this:
intent:#Intent;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;i.res_id=80;end
But when I click on it, nothing happens, and I see this in the logs:
chromium: [INFO:CONSOLE(0)] "Navigation is blocked: intent:#Intent;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;i.res_id=80;end", source: http://example.com/?res_id=80 (0)
I then read about this on Chrome documentation, which interestingly, their example was using a custom scheme, contrary to what they had argued before should not be done!
Now if I add the HTTP scheme to my intent link, like this:
intent://example.com/?res_id=80#Intent;scheme=http;package=com.example.project;component=com.example.project/.ui.ActivityWithResource;end
Then it works, because the activity has the intent-filter to handle the urls like http://example.com/, but why when I specify the component, it doesn't work?
Also, when I use HTTP scheme in my intent, in shows activity resolver (except android 6.0 as I do use auto-verify), but I assume if I can get my explicit intent link to work, it should directly open the resource in the app, as I already have defined the component in the intent link. right?
Maybe the only way is to use custom scheme after all?
Thanks
P.S: Here is the activity definition in my AndroidManifest. I wasn't sure if it requires android:pathPrefix to work or not, so I added both intent-filters
<activity
android:name=".ui.ActivityWithResource"
android:label="#string/app_name"
android:exported="true"
android:screenOrientation="portrait">
<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="example.com" android:pathPrefix="/"/>
</intent-filter>
<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="example.com"/>
</intent-filter>
</activity>
I am trying to open my app from a website and read some text from link. The URL will be like codespike.com/?code=xxxx. I need to read the xxx but my problem is that I am not able to open my app when this specific URL in being opened in the browser. For testing I also used a webiste bfinstafollowers.com, not working with this either.
This is what I am trying.
<activity
android:name="com.softech.betforinstafollowers.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:host="bfinstafollowers.com" android:scheme="http"
android:pathPrefix=".*"/>
</intent-filter>
</activity>
also tried with <category android:name="android.intent.category.BROWSABLE"/> and without android:pathPrefix=".*" but my app doesnt open.
Solved my issue, as it turns out regular http, https doesn't work. I had to create my custom scheme for this purposes.
I am trying to create an URL scheme for my Android application but when i enter the link in the browser it opens the link not the app. So far my code looks like this. The link is formed like this http://myhost.com .
<activity android:name=".activities.OpenSchemeActivity"
android:label="#string/activity_open_scheme"
android:screenOrientation="portrait"
android:exported="true"
android:launchMode="singleTask">
<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="myhost.com"/>
</intent-filter>
</activity>
Does anyone have any idea why is not working?
Sorry to say that it will NOT work directly from the browser's address bar. No way. Only further server redirects or link clicks can lead you to an app picker. As far as I know, browser doesn't handle URL schemes being typed into address bar as something that could require an Intent call.