Skip to content

Commit

Permalink
added android support for deep link and change icon
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Jan 23, 2024
1 parent 99612aa commit 962925c
Show file tree
Hide file tree
Showing 29 changed files with 82 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/wallet/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:label="Web3Wallet"
android:label="Web3Wallet Flutter"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,65 @@
package com.walletconnect.flutterwallet

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.annotation.NonNull

import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.EventChannel
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class MainActivity: FlutterActivity() {
private val eventsChannel = "com.walletconnect.flutterwallet/events"
private val methodsChannel = "com.walletconnect.flutterwallet/methods"

private var initialLink: String? = null
private var linksReceiver: BroadcastReceiver? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val intent: Intent? = intent
initialLink = intent?.data?.toString()

EventChannel(flutterEngine?.dartExecutor?.binaryMessenger, eventsChannel).setStreamHandler(
object : EventChannel.StreamHandler {
override fun onListen(args: Any?, events: EventChannel.EventSink) {
linksReceiver = createChangeReceiver(events)
}
override fun onCancel(args: Any?) {
linksReceiver = null
}
}
)

MethodChannel(flutterEngine!!.dartExecutor.binaryMessenger, methodsChannel).setMethodCallHandler { call, result ->
if (call.method == "initialLink") {
if (initialLink != null) {
result.success(initialLink)
}
}
}
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if (intent.action === Intent.ACTION_VIEW) {
linksReceiver?.onReceive(this.applicationContext, intent)
}
}

fun createChangeReceiver(events: EventChannel.EventSink): BroadcastReceiver? {
return object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val dataString = intent.dataString ?:
events.error("UNAVAILABLE", "Link unavailable", null)
events.success(dataString)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
</adaptive-icon>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#F5EDFF</color>
</resources>
8 changes: 2 additions & 6 deletions example/wallet/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Web3Wallet</string>
<string>Web3Wallet Flutter</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Web3Wallet</string>
<string>web3wallet_flutter</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
Expand Down Expand Up @@ -64,9 +64,5 @@
</array>
<key>FlutterDeepLinkingEnabled</key>
<true/>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>web3modalflutter</string>
</array>
</dict>
</plist>
12 changes: 5 additions & 7 deletions example/wallet/lib/dependencies/deep_link_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class DeepLinkHandler {

static void checkInitialLink() {
try {
_methodChannel.invokeMethod('initialLink');
_methodChannel.invokeMethod('initialLink').then(
_onLink,
onError: _onError,
);
} catch (e) {
debugPrint('[DeepLinkHandler] checkInitialLink $e');
}
Expand All @@ -36,12 +39,7 @@ class DeepLinkHandler {
}) async {
await Future.delayed(Duration(milliseconds: delay));
try {
final canLaunch = await canLaunchUrlString(scheme);
if (canLaunch) {
launchUrlString(scheme, mode: LaunchMode.externalApplication);
} else {
throw Exception('Can not launch scheme');
}
await launchUrlString(scheme, mode: LaunchMode.externalApplication);
} catch (e) {
debugPrint('[DeepLinkHandler] error re-opening dapp ($scheme). $e');
_goBackModal(title: modalTitle);
Expand Down
2 changes: 1 addition & 1 deletion example/wallet/lib/dependencies/web3wallet_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Web3WalletService extends IWeb3WalletService {
description: 'Web3Wallet Flutter Example',
url: 'https://walletconnect.com/',
icons: [
'https://images.prismic.io/wallet-connect/65785a56531ac2845a260732_WalletConnect-App-Logo-1024X1024.png'
'https://raw.githubusercontent.com/WalletConnect/WalletConnectFlutterV2/master/example/wallet/AppIcon.png'
],
redirect: Redirect(
native: 'wcflutterwallet://',
Expand Down

0 comments on commit 962925c

Please sign in to comment.