Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on android, handle file received from intent action_view #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kppro
Copy link

@Kppro Kppro commented Mar 10, 2021

On Android this allows to receive media also from the intent action_view.

Example use case : clic on an email attachment to open it with our app

@filipenanclarez
Copy link

filipenanclarez commented Feb 6, 2022

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

@LuisMiguelSS
Copy link

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

This won't work for all files as you'll get permission issues, this plugin should still be able to send the content set when adding the intent extra "EXTRA_STREAM".

@jaroslawdabrowski
Copy link

This pull request, looks very promising as I am facing the same issue. Can it get merged?

@YashSavsani
Copy link

Can this branch get merged?

@Kppro
Copy link
Author

Kppro commented Jul 18, 2023

Can this branch get merged?

doesn't look like this repo is maintained anymore. Soon there will be more forks than stars 😢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants