receive_sharing_intent
receive_sharing_intent copied to clipboard
ACTION_VIEW support
I thank you for this amazing package , but can you please add the support for ACTION_VIEW the same way you implemented ACTION_SEND ? This is an issue not just a feature request because when I use action_view it copies the file content uri (which is useless for flutter) to the shared text and copies nothing to the shared files (where it suppose to copy the absolute path of the file) (pdf to be exact)
It is, but not officially and almost hidden:
import 'package:flutter_absolute_path/flutter_absolute_path.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
/// checking if we were redirected from the web site
if (data.startsWith('http')) {
scaffoldCompleter.future.then((scaffoldContext) =>
Scaffold.of(scaffoldContext).showSnackBar(SnackBar(
content: Text(S.of(context).youveBeenRedirectedToTheLocalApp),
)));
return;
} else {
/// seems to be an opened file
/// ... which is awfully encoded as a content:// URI using the path as **queryComponent** instead of as **path** (why???)
/// unfortunately, android needs to copy the file to our own app directory
/// TODO: don't copy files we can directly read
print(data);
String path = await FlutterAbsolutePath.getAbsolutePath(data as String);
print(path);
data = [
SharedMediaFile(
path, base64Encode(kTransparentImage), null, SharedMediaType.FILE)
];
_sharedFiles = data;
}
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="*/*" /> <!-- application/x-xopp -->
<!--
Work around Android's ugly primitive PatternMatcher
implementation that can't cope with finding a . early in
the path unless it's explicitly matched.
-->
<data android:host="*" />
<data android:pathPattern=".*\\.xopp" />
<data android:pathPattern=".*\\..*\\.xopp" />
<data android:pathPattern=".*\\..*\\..*\\.xopp" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.xopp" />
<!-- keep going if you need more -->
</intent-filter>
^ What is data?
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();
...
});