首页 > 解决方案 > 如何在 fyne android 应用程序的深层链接中访问参数值?

问题描述

我正在开发一个 Fyne 应用程序,该应用程序将被编译并安装为 Android 应用程序。

该应用程序允许用户使用 oauth2 进行身份验证。身份验证服务器将身份验证代码作为参数值在 url 字符串中返回给应用程序。我能够建立一个深层链接并通过深层链接打开我的 fyne 应用程序,但不知道如何访问意图的数据字符串以解析参数值。

对 Google 的广泛研究只展示了 Kotlin/Java 中的解决方案,没有提到任何人在 Golang 或 Fyne 项目中实现了这一点。

项目的AndroidManifest.xml的activity部分如下

<activity
            android:label="myapp"
            android:name="org.golang.app.GoNativeActivity"
            android:configChanges="0xa0">
            <meta-data
                android:name="android.app.lib_name"
                android:value="myapp" />
            <intent-filter>
                <action
                    android:name="android.intent.action.MAIN" />
                <category
                    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter 
                android:label="@string/oauth2_deep_link">
                <!-- below for Deep Linking -->
                <action 
                    android:name="android.intent.action.VIEW" />
                <!-- allows your app to respond to implicit intents. Without this, the activity can be started only if the intent specifies your app component name.-->
                <category 
                    android:name="android.intent.category.DEFAULT" />
                <!-- BROWSABLE required for intent-filter to be accessible from browser-->
                <category 
                    android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with "myapp://oauth2/code” -->
                <data 
                    android:scheme="myapp"
                    android:host="oauth2" />
                
            </intent-filter>
        </activity>

我希望使用 url “myapp://oauth2/?code=kalksdnfaldsfn”将身份验证代码返回给应用程序

对Kotlin不太了解,但我认为这可以通过使用类似以下函数的东西在Kotlin中实现。

fun Intent.getData(key: String): String {
    return extras?.getString(key) ?: "intent is null"
}

Golang 是否有一个库来实现这一点?

标签: godeep-linkingandroid-deep-linkfyne

解决方案


推荐阅读