I’m currently developing a Flutter app where I need to trigger specific actions based on the content of QR code. Which is VCARD and MATMSG scheme in my case. However, I’m facing issues getting the app to recognize and process these schemes correctly.
The goal is to trigger contact details for VCARD and open an email client for MATMSG.
Here is the code block that I try to trigger specific action.
Future<void> onTapActionButton() async {
late String content;
if (documentDetail!.type == DocumentType.TEXT) {
content = TextQrModel.searchUrl(documentDetail!.content);
} else {
content = documentDetail!.content;
}
final uri = Uri.tryParse(content);
if (uri == null) {
unawaited(showErrorDialog('No available data found.'));
return;
}
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
unawaited(showErrorDialog('No available data found.'));
}
}
Content variable in above function for my cases are
For Vcard:
BEGIN:VCARD
N:;q
FN:q
ORG:
TITLE:
TEL;WORK;VOICE:
TEL;CELL:
TEL;FAX:
EMAIL;WORK;INTERNET:
URL:
END:VCARD
For MATMSG:
MATMSG:TO:[email protected];SUB:;BODY:;;
I am using
url_launcher: ^6.3.0
For the MATMSG scheme I get the following error
PlatformException(ACTIVITY_NOT_FOUND, No Activity found to handle intent { matmsg:TO:[email protected];SUB:;BODY:;; }, null, null)
For the VCARD scheme I get the following error
PlatformException(ACTIVITY_NOT_FOUND, No Activity found to handle intent { begin:VCARD%0AN:;q%0AFN:q%20%0AORG:%0ATITLE:%0ATEL;WORK;VOICE:%0ATEL;CELL:%0ATEL;FAX:%0AEMAIL;WORK;INTERNET:%0AURL:%0AEND:VCARD }, null, null)
Here is my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sms" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<application
android:label="mobile_app"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:taskAffinity=""
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
<queries>
<intent>
<action android:name="android.intent.action.PROCESS_TEXT"/>
<data android:mimeType="text/plain"/>
</intent>
</queries>
</manifest>