Flutter deep links not working from browser - android

I made changes in Android manifes as suggested here:
https://docs.flutter.dev/development/ui/navigation/deep-linking
So, new metadata and config has been added to MainActivity:
<!-- Deep linking -->
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<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="flutterbooksample.com" />
<data android:scheme="https" />
</intent-filter>
As a result, when I use adb for testing as they said to do:
adb shell am start -a android.intent.action.VIEW \
-c android.intent.category.BROWSABLE \
-d "http://flutterbooksample.com/book/1"
I am getting what I want:
But if I try to open url http://flutterbooksample.com/book/1 directly in browser on my emulator, nothing happens, browser opens page and theres no prompt to open url in my app.
Do I need to do anything else to make it working?

Short Answer
You can't call the deep link URL from the web browser's search bar. First, you need to create an HTML page. Then you can click the link. It will work.
More details
In my case, I created an HTML file with a deep link and send it to my email.
HTML file
Open my app
AndroidManifest.xml
<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="test"
android:scheme="myapp" />
</intent-filter>

Related

Deep link with # in url is not redirecting to app

I have a deep link URL that I want to match for a specific activity of my app:
https://example.com/#/auth
The problem is with # in my URL, when I omit it, deep-link works fine. but with # deep link is opening chrome instead of my app.
Here are the manifest meta tags:
<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="example.com" android:pathPrefix="/#/auth"/>
</intent-filter>

Android app link only works from adb

I want my app to be launched when a link with a specific, custom scheme is clicked on.
But it only works from adb with:
./adb shell a start -a Android.Intent.Action.VIEW -d "ghd://whateversite.com"
It doesn't work when a link is clicked, or the URL is written directly in the browser.
I'm using:
<activity
android:name=".link.LaunchActivity"
android:theme="#android:style/Theme.NoDisplay">
<intent-filter>
<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="ghd" />
</intent-filter>
</activity>
Set android:host too in the Intent filter
<activity
android:name=".link.LaunchActivity"
android:noHistory="true"
android:theme="#android:style/Theme.NoDisplay">
<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="ghd" android:host="whateversite.com" />
</intent-filter>
</activity>
Try to remove the autoVerify=true from your <intent-filter/>. As said in the documentation :
When the android:autoVerify attribute is present, installing your app causes the system to attempt to verify all hosts associated with the web URIs in all of your app's intent filters. The system treats your app as the default handler for the specified URI pattern only if it successfully verifies all app link patterns declared in your manifest.
Since you didn't add any host, this might be why it is not working.

Android app indexing - deep linking for urls with GET params like www.abc.com?parameter=value

I'm creating a intent-filter in order to filter in my app urls like https://www.hotelsclick.com/?hotel_id=135738
I see in the documentation that I should create an intent filter like
<intent-filter android:label="#string/filter_title_viewgizmos">
<action android:name="android.intent.action.VIEW" />
<!-- Accepts URIs that begin with "http://example.com/gizmos” -->
<data android:scheme="http"
android:host="example.com"
android:pathPrefix="/gizmos" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
This intent-filter should filter URLs like "http://example.com/gizmos?1234, http://example.com/gizmos/1234, http://example.com/gizmos/toys/1234"
That's good but... my URL is different, it's like http://example.com?toys=1234 'cause it's got a named GET parameter just in the home page, which is hotel_id.
How can I filter such URLs? Is there some more parameter to put in the intent-filter definition?
Edit: I put the following intent-filter in my Manifest.xml
<intent-filter android:label="#string/app_name">
<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="hotelsclick.com" />
<data android:scheme="http"
android:host="hotelsclick.com" />
</intent-filter>
and I CAN open the app by providing this ADB command
adb shell am start -a android.intent.action.VIEW -d "http://hotelsclick.com?hotel_id=135738" com.towers.hotelsclick
BUT it doesn't work from the page self-generated with the deep-link tool: https://developers.google.com/app-indexing/webmasters/test?hl=it
I put in the webpage the following URI in the editText: "android-app://com.towers.hotelsclick/hotelsclick.com?hotel_id=135738" and I got this page: https://applinktest.appspot.com/app-link.html?url=android-app%3A%2F%2Fcom.towers.hotelsclick%2Fhotelsclick.com%3Fhotel_id%3D135738
As you can see the link in the page is intent://#Intent;scheme=hotelsclick.com?hotel_id=135738;package=com.towers.hotelsclick;end and I expected this intent-link to be opened by the app itself when clicked on mobile on the same phone I used for the adb command before. But it doesn't work and takes me straight to the google play store, suggesting to open the app from there
So, since I can make the intent-filter work via ADB but not with a proper link, can I say I succeeded or not?
Thank you
The generated link is not valid. It should be
intent://hotelsclick.com?hotel_id=135738#Intent;scheme=http;package=com.towers.hotelsclick;end
instead of
intent://#Intent;scheme=hotelsclick.com?hotel_id=135738;package=com.towers.hotelsclick;end

Deeplinking to an android app

Can we implement deeplinking for a mobile app without having a website or do we have to have a predefined specific website to implemment it?
Deep linking can work without having a specific website. All you need for it to work is add the <intent-filter> ... </intent-filter> tag to your preferred activity via the AndroidManifest.
Then create a unique URI pattern intended to match any HTTP URI such as http://your-app-domain/content or a custom scheme such as your-app://content. Add this scheme to the <data ... /> tag.
Here's what your activity should look like when you're done.
<activity
android:name=".activities.DeepLinkingActivity"
android:label="#string/title_activity_deeplink">
<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="your-app-domain"
android:pathPrefix="/content"
android:scheme="http" />
</intent-filter>
</activity>
Regardless of the URI scheme you choose, you should be able to begin your activity when an intent with the scheme is triggered.
If you are familiar with adb commands, enter this command
adb shell am start -a android.intent.action.VIEW -d "http://your-app-domain/content" com.your-app-package
Further reading https://developers.google.com/app-indexing/android/app

Android deep linking works in ADB, but not browser

I am trying to add deep linking to my app. I have added 2 intent filters to one of my activities, one filter for the "http" scheme, and another for my custom scheme (I'm using "example"). I have added one intent filter per scheme, based on the info in this SO (Deep-linking intent does not work), so that I can handle both example://test and http://www.example.com/test type of links.
Here is my XML:
<activity
android:name="com.myapp.myapp.SplashActivity"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter android:label="Intent Filter label">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- Accepts URIs that begin with "http://www.example.com/test2” -->
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/test2" />
</intent-filter>
<intent-filter android:label="Intent Filter label">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.LAUNCHER" />
<!-- Accepts URIs that begin with "example://test2” -->
<data android:scheme="example"
android:host="test2" />
</intent-filter>
</activity>
They are loading correctly when I test in ADB:
adb shell am start -W -a android.intent.action.MAIN -d "example://test2" com.myapp.myapp
returns
Starting: Intent { act=android.intent.action.MAIN dat=example://test2 pkg=com.myapp.myapp }
Status: ok
Activity: com.myapp.myapp/com.app.myapp.SplashActivity
ThisTime: 357
TotalTime: 357
Complete
However, I get absolutely nothing in a browser. When I try this in a browser:
"example://test2" in FF I get "couldn't find an app to open this link" and in Chrome and the Native Browser, it opens up new Google search for "example://test2".
When I try the other style: "http://www.example.com/test2" it just tries to navigate to that web page in all 3 browsers.
I am deploying the app to my phone from Android Studio. I have also tried by generating a debug APK, sending it to my phone, and installing. Same result for both.
What am I doing wrong? I've followed the guide (https://developer.android.com/training/app-indexing/deep-linking.html) to the letter as far as I can tell. Does my app need to be in the store for the deep linking to work?
Ughh, my action was MAIN when it should have been VIEW...
<intent-filter>
<action android:name="android.intent.action.MAIN" />
...
<intent-filter>
<action android:name="android.intent.action.VIEW" />
Your implementation seems to be correct and also, if you're testing your app in your device, it does not need to be available on Playstore.
Have you tried testing through a QR code? As is demonstrated in Google documents - https://developers.google.com/app-indexing/android/test
Hope this helps.
The scheme (and probably host) have to be in all lower case.
From the uni_link package i copied the deep link 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" />
<!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
<data
<!-- THIS HAS TO BE IN ALL LOWER CASE -->
android:scheme="[YOUR_SCHEME]"
<!-- android:scheme="[your_scheme]" -->
android:host="[YOUR_HOST]" />
</intent-filter>
and pasted in my package name com.myPackage.app as the scheme. For the host I put localhost.
Changing the scheme to all lower case com.mypackage.app allowed the deep link to work.
You can use this site to test the deep link without using adb.
PS: This is not true for iOS where the CFBundleURLName and CFBundleURLSchemes can contain uppercase letters.

Categories

Resources