yebowhatsay
yebowhatsay

Reputation: 341

How to access parameter values in a deep link on a fyne android app?

I am working on a Fyne app that is to be compiled and installed as an Android app.

The app allows a user to authenticate using oauth2. The authentication server returns the auth code back to the app in the url string as parameter values. I am able to make a deep link and through the deep link open my fyne app, but have no idea how to access the data string of the intent in order to parse the parameter values.

Extensive research on Google only shows solutions in Kotlin/Java with no mention of anyone achieving this in Golang or a Fyne project.

The activity part of the AndroidManifest.xml of the project is as follows

<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>

I am hoping the return the auth code back to the app using the url "myapp://oauth2/?code=kalksdnfaldsfn

Don't know much about Kotlin, but I think this can be achieved in Kotlin by using something like the following function.

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

Does Golang have a library to achieve this?

Upvotes: 0

Views: 275

Answers (0)

Related Questions