KasemJaffer / receive_sharing_intent

A Flutter plugin that enables flutter apps to receive sharing photos, text and url from other apps.
Apache License 2.0
334 stars 391 forks source link

Added support for android view intent action #160

Closed odam1 closed 3 years ago

GRBurst commented 3 years ago

I added some representative change request, but there is more of your personal ids that need to be reverted ;-)

filipenanclarez commented 2 years ago

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