Add the ability to launch app from Crypto QR codes

This commit is contained in:
OmarHatem28 2022-08-09 13:34:40 +02:00
parent 71f768e6b0
commit 01adf863d0
2 changed files with 46 additions and 0 deletions

View file

@ -38,6 +38,15 @@
android:scheme="cakewallet"
android:host="y.at" />
</intent-filter>
<!-- bitcoin qr code scheme -->
<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="bitcoin" />
<data android:scheme="monero" />
<data android:scheme="litecoin" />
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"

View file

@ -202,6 +202,8 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
super.initState();
//_handleIncomingLinks();
//_handleInitialUri();
initUniLinks();
}
@override
@ -210,6 +212,41 @@ class AppState extends State<App> with SingleTickerProviderStateMixin {
super.dispose();
}
/// handle app links while the app is already started - be it in
/// the foreground or in the background.
Future<void> initUniLinks() async {
try {
stream = getLinksStream().listen((String link) {
handleDeepLinking(link);
});
final String initialLink = await getInitialLink();
handleDeepLinking(initialLink);
} catch (e) {
print(e);
}
}
void handleDeepLinking(String link) async {
if (link == null || !mounted) return;
final List<String> urlComponents = link.split(":");
switch (urlComponents.first) {
case "bitcoin":
print("@@@@@@@@@@@@@@@@@@@@@@@@@@");
print("Bitcoin QR Code: \n${link}");
break;
case "litecoin":
case "haven":
case "monero":
default:
print("@@@@@@@@@@@@@@@@@@@@@@@@@@");
print(link);
}
}
Future<void> _handleInitialUri() async {
try {
final uri = await getInitialUri();