receive_sharing_intent icon indicating copy to clipboard operation
receive_sharing_intent copied to clipboard

how to handle android.intent.action.VIEW?

Open llyl opened this issue 4 years ago • 2 comments

I want to receive a file via action.VIEW, what should I do?

Add following codes only to AndroidManifest is not working: <data android:mimeType="application/octet-stream" />

llyl avatar May 25 '21 02:05 llyl

image

llyl avatar May 25 '21 02:05 llyl

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