I’m building a mobile app with Flutter & I would like a link to redirect to my mobile app (if you type youtube.com on your mobile browser it redirects you on the YouTube app if you have it on your phone)
I have edit my android/app/src/main/AndroidManifest.xml file like this :
(I want tu use uni_links)
<activity // default stuff here>
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</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" />
<!-- Accepts URIs that begin with https://YOUR_HOST -->
<data
android:scheme="https"
android:host="api.area.baptiste.zip" />
</intent-filter>
</activity>
And this is the code of the app :
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
StreamSubscription? _sub;
final params = "null";
Future<void> initUniLinks() async {
print("initUniLinks is working");
_sub = linkStream.listen((String? link) {
print("listener is working");
// do something with link
if (link != null) {
var uri = Uri.parse(link);
if (uri.queryParameters['id'] != null) {
print(uri.queryParameters['id'].toString());
}
}
}, onError: (err) {
// do something with error
});
}
@override
void initState() {
// TODO: implement initState
super.initState();
initUniLinks();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text("App link demo"),
),
body: const Text("Home Page"),
);
}
}
On the flutter doc they say that I have to give acces to a json file so I serve it at this adresse : assetlinks.json & I verify the succes of this file with this google tool : digital asset link
My probleme is that with all this modifications, when I build the APK, install it on my phone and then go on this link api.area.baptiste.zip, nothing appened, I just receive a 404 error.
I also try to lunch the app on my emulator with the command flutter run
and then do this adb command : adb shell "am start -W -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d https://api.area.baptiste.zip/test/?id=123"
but nothing append.
https://api.area.baptiste.zip is the root of a NestJS API, I don’t know if it can affect the good workinng of what I want to do.
2
Answers
if you type youtube.com on your mobile browser it redirects you to the YouTube app – it’s wrong. I tried it. by the way.
You don’t need to use any 3rd party package to redirect to your app from the browser. but you need html anchor tag to redirect your app means you need html page.
The below link will open your app if your app is installed on the user’s device.
to test click here to open your app . I just link-up the above url and it’ll jump to your app if the scheme and host name is exactly the same.
Taking a look at your
assetlinks.json
file, you have only specified only 1 sha256 fingerprint. It is possible that is a release sha256 fingerprint you added but you are testing with the debug app.It is also possible that it is the debug sha256 fingerprint you added but you are testing with the release app.
To fix this, add the sha256 fingerprints for debug and release mode to the file. The
sha256_cert_fingerprints
accepts a list of fingerprints so you should be able to add another one.Try running the app again after updating the value and perform the operation again.