top of page

[Flutter/dart] Unable to link with other apps on Android


Phenomenon


At one point, I couldn't open another app from one app.

More specifically, in my app I could open a website in the browser app or contact me in the email app, but that was getting an error.



Detail


The following processing is performed using a package called url_launcher.


static Future<void> openEmailPage({BuildContext context, String subject, 
                                   String to})async{
  Uri _uri=Uri(
    scheme: 'mailto',
    path: to,
    queryParameters: {
      'subject': subject,
    }
  );
  String _uriStr=_uri.toString();

  bool _res=await canLaunch(_uriStr);     //※
  if (_res){
    await launch(_uriStr); 
  }
  else{
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text('Error')
      )
    );
  }
}

This canLaunch () returns false.



Cause


When targetSdkVersion is set to 30 or more, it seems that it has to be clearly stated when linking with other apps. (reference)



Solution


Just specify the apps to use for Android Manifest. You can write it individually for each application, but since it can be set collectively for each Intent Filter, use that (see the above site).


<queries>
    <intent>
        <action android:name="android.intent.action.SEND" />
        <data android:mimeType="*/*" />
    </intent>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
</queries>

My app uses a web browser, email, and twitter, so I was able to handle it above.

See here for which apps use which Intent Filter.


Note1


If the version of gradle plugin is old, you get a compile error "unexpected element <queries> found in <manifest>". (reference)


In this case, edit the following part of the project level build.gradle to upgrade the version.

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.4'
    ・・・
}

See here for which version to upgrade.


Note2


After changing the above settings, do flutter clean. I forgot this and the setting changes were not reflected.

Recent Posts

See All

[C] Array of function pointers

What want to do As stated in the title, I would like to define an array of function pointers. Specifically, for example, the third...

Comments


category

Let's do our best with our partner:​ ChatReminder

iphone6.5p2.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Let's do our best with our partner:​ ChatReminder

納品:iPhone6.5①.png

It is an application that achieves goals in a chat format with partners.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png

Theme diary: Decide the theme and record for each genre

It is a diary application that allows you to post and record with themes and sub-themes for each genre.

google-play-badge.png
Download_on_the_App_Store_Badge_JP_RGB_blk_100317.png
bottom of page