receive_sharing_intent
receive_sharing_intent copied to clipboard
how to handle android.intent.action.VIEW?
I want to receive a file via action.VIEW, what should I do?
Add following codes only to AndroidManifest is not working:

intent.action.VIEW is handled in package as url type. When user try open a file, android system send the uri of this file to intent.
if you need open file with dart:io functions like readAdBytes or readAsString, you should convert the Uri to full path. You can do this with uri_to_file package.
So, you can handle action.VIEW with this code in flutter side:
import 'package:uri_to_file/uri_to_file.dart';
...
// For sharing or opening urls/text coming from outside the app while the app is closed
ReceiveSharingIntent.getInitialText().then((String? value) async {
String _sharedText = value ?? "";
debugPrint('path of file: ${Uri.parse(_sharedText).path}');
File file = await toFile(_sharedText);
var fileContent = await file.readAsString();
...
});