[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 AllPhenomenon There is an array Check whether the index variable is within the size of the array, and access the element only if it is within the size. I tried to do something common. val array = Seq.fil
Overview When communicating data using a Queue, the following operations are possible: Queue.io.enq.valid: When set to false, data will not be added. Queue.io.deq.valid: When set to false, data will n
What I want to do There are multiple similar units Most of processes are the same, only some differences. Select an appropriate unit depending on the conditions and execute the process What I tried to