[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 AllWhat want to do There is an operation that operates on two-dimensional arrays There are multiple targets to be processed In this case, I...
What want to do As stated in the title, I would like to define an array of function pointers. Specifically, for example, the third...
Phenomenon There is an array Check whether the index variable is within the size of the array, and access the element only if it is...
Comments