receive_sharing_intent icon indicating copy to clipboard operation
receive_sharing_intent copied to clipboard

ACTION_VIEW support

Open phaylali opened this issue 5 years ago • 4 comments

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)

phaylali avatar Apr 20 '20 22:04 phaylali

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>

TheOneWithTheBraid avatar Aug 05 '20 10:08 TheOneWithTheBraid

^ What is data?

marcqtan avatar Oct 21 '20 02:10 marcqtan

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();
    ...
});

filipenanclarez avatar Feb 06 '22 23:02 filipenanclarez