앱에서 접근할 수 있는 파일을 시스템 기본 애플리케이션으로 열 수 있도록 해주는 플러터 플러그인입니다. Android, iOS, Web, macOS, Windows, Linux에서 크로스플랫폼 파일 실행을 지원하여 플랫폼별 코드를 작성하지 않고도 앱에 파일 열기 기능을 쉽게 통합할 수 있습니다. 이 플러그인은 앱의 디렉토리 내 파일이나 파일 선택기로 선택된 파일과 같은 앱이 접근 권한이 있는 파일과 함께 작동합니다.
사용 사례
다운로드한 문서 열기
이미지 또는 PDF 시작
네이티브 앱과 파일 공유
파일 미리보기 통합
사용자 중심 파일 작업 활성화
주요 기능
크로스 플랫폼 호환성
시스템 기본 앱 사용
모든 주요 운영 체제를 지원합니다
파일 열기용 간단한 API
부여된 권한을 통한 안전한 파일 접근
적합한 대상
파일 관리 앱
문서 뷰어
미디어 플레이어
생산성 도구
파일 공유가 필요한 앱
고려 사항
적절한 파일 권한이 필요합니다
앱이 액세스할 수 있는 파일에 한정
플랫폼별 동작은 다를 수 있습니다
파일 생성을 처리하지 않음
웹 지원은 브라우저 기능에 따라 달라집니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
open_file
A plugin to open files the app has permission to access with default system-provided applications.
Supports Android, iOS, Web, Linux, macOS and Windows.
does not include REQUEST_INSTALL_PACKAGES permission on Android, so cannot install .apk's
does not include READ_EXTERNAL_STORAGE permission on Android
has completely rewritten Android implementation for more robust permission checks
has deprecated explicit list of MIME types, UTI's, and Linux launch options
web implementation is changed (see below)
The main use case for the plugin is opening a generated or downloaded file with a default system application (see example).
Usage
Add open_file as a dependency in your pubspec.yaml file.
dependencies:open_app_file:^lastVersion
Example
import'package:open_app_file/open_app_file.dart';
OpenAppFile.open('/sdcard/example.txt');
// You can provide overrides for MIME type (Android) and/or UTI (iOS). This is not necessary// in most cases, but if you know that the file extension does not match its content, you can// help the system to provide correct response to your request.OpenAppFile.open('/sdcard/example.abc', mimeType: 'text/plain', uti: 'public.plain-text');
Behavior on Android
While the main purpose of the plugin is opening files owned by the host app, it is possible
to open any file even considering Android 11 scoped storage limitations
(see official docs).
The plugin will not provide any tools for requesting permissions to prevent declaring
them in the Manifest for apps that don't need to handle this case.
An attempt to open a file with no permissions granted will produce an appropriate result
(ResultType.permissionDenied).
See more details and instructions on how to test permission conditions in the example app.
Behavior on web
Direct local file access is generally discouraged on web, therefore we chose the approach that in
most cases is the most logical web alternative: imitate user clicking on an element that targets the requested file.
For most files it will result in browser downloading the requested file immediately.
Some file types, like images, texts, or videos might be opened directly, so the library adds target: _blank attribute
to prevent user from leaving the application by accident.
The important limitation of this approach is that there's no way to check file type or availability
beforehand, so on web the open call always succeeds.
Check the example app for general idea on how app-generated or remote files can be handled on web.