Convert intent web url to Android Intent

715

I don't know if you can execute native kotlin/java code when using flutter, but this can be solved (natively) by using the following code (taken from https://stackoverflow.com/a/35612860):

override fun shouldOverrideUrlLoading(view: WebView?, url: String): Boolean {

        if (url.startsWith("intent://")) {
            val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
            return if (intent.resolveActivity(context.packageManager) != null) {
                context.startActivity(intent)
                true
            } else {
                // handle error, e.g. open playstore
                true
            }
        }
        /* 
          Rest of override url handling
          ...
        */
    }

On Android API 30+ intent.resolveActivitywill only detect the installed twint app if you have the following entry in your AndroidManifest.xml:

<queries>
    <intent>
        <action android:name="ch.twint.action.TWINT_PAYMENT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="twint" />
    </intent>
</queries>
Share:
715
alexdess
Author by

alexdess

Currently 25 years old, I have a Bachelor's degree in computer science at the University of Engineering and Architecture in Fribourg, member of the University of Applied Sciences of Western Switzerland. I am continuing my education by doing a Master's degree at 50% in conjunction with my position as an engineer at Burning Box S.A. My main hobbies are sports (basketball and skiing) as well as travelling to discover the world. I am also a basketball referee, a role that has taught me to keep my cool in all circumstances, to manage my authority by making me respected and to improve my speech.

Updated on November 25, 2022

Comments

  • alexdess
    alexdess over 1 year

    I currently integrate a webview (webview_flutter: 2.0.4) in my application for a payment process. Unfortunately, at some point the following url is launched:

    intent://payment#Intent;action=ch.twint.action.TWINT_PAYMENT;scheme=twint;S.code=18223;S.startingOrigin=EXTERNAL_WEB_BROWSER;S.browser_fallback_url=;end
    

    This URL should launch the "twint" application (Swiss payment solution) Unfortunately it doesn't work so I'm trying to recreate the corresponding android intent (android_intent: 2.0.0) but I can't.

    Can anyone help me or any other idea for a solution?

    I also tried with the url_launcher extension but I don't think it's the right solution.

    • alexdess
      alexdess about 3 years
      Any idea for my question ?
    • Christophe Rodriguez
      Christophe Rodriguez over 2 years
      Did you solve your problem?
    • M.Yogeshwaran
      M.Yogeshwaran over 2 years
      have you solved it??
  • alexdess
    alexdess almost 3 years
    I will try your solution ASAP. It's effectively possible to execute native android code in flutter.
  • Esteban Chornet
    Esteban Chornet over 2 years
    Hi @alexdess, does this solution work if you have several twint apps installed? Like CreditSuisse Twint, BVC Twint, etc. Does it open the android native popup to select the app you want to pay with?
  • fullStackChris
    fullStackChris about 2 years
    @EstebanChornet - also wondering the same. In this situation, iOS has an advantage in that the specific app desired is embedded in the link to the app. It seems Android only identifies it by the "action" name, which is always ch.twint.action.TWINT_PAYMENT - perhaps there is an additional "extra" key value pair you could send to specify the app? I've found no TWINT documentation around this.