Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri

Overview


File Opener

@capacitor-community/file-opener

Capacitor File Opener. The plugin is able to open a file given the mimeType and the file uri.


Table of Contents

Maintainers

Maintainer GitHub Active
ryaa ryaa yes

About

This plugin is similar to cordova-plugin-file-opener2 but without installation support. The plugin supports Android platform only.

Installation

npm install @capacitor-community/file-opener
npx cap sync

API

open(...)

open(options: FileOpenerOptions) => Promise<void>

Method to open a file.

Param Type
options FileOpenerOptions

Since: 1.0.0


Interfaces

FileOpenerOptions

file open method options

Prop Type Description Since
filePath string file path 1.0.0
contentType string MIME type (optional) 1.0.0
openWithDefault boolean Use the default platform chooser, if true, otherwise: On Android: it will show "Open File in.." title of the chooser dialog, the system will always present the chooser dialog even if the user has chosen a default one and if no activity is found to handle the file, the system will still present a dialog with the specified title and an error message No application can perform this action On iOS: it will presents a menu restricted to a list of apps capable of opening the current document. This determination is made based on the document type and on the document types supported by the installed apps. To support one or more document types, an app must register those types in its Info.plist file using the CFBundleDocumentTypes key. (optional) default value is true 1.0.0

List of Error Codes and Meanings

When an error is thrown, one of the following codes (as a string value) will be used.

Code Description
'1' INTERNAL_ERROR
'2' INVALID_ARGUMENT
' '8' FILE_NOT_SUPPORTED
'9' FILE_NOT_FOUND
'10' UNKNOWN

Android

If you app needs to open files in the external directories, then within your AndroidManifest.xml file, change the following:

+ ">



+  

Comments
  • ERROR in ./node_modules/@capacitor-community/file-opener/dist/esm/index.js 3:0-30

    ERROR in ./node_modules/@capacitor-community/file-opener/dist/esm/index.js 3:0-30

    I'm building an app with create-react-app and am getting the following error when adding file-opener.

    ERROR in ./node_modules/@capacitor-community/file-opener/dist/esm/index.js 3:0-30 Module not found: Error: Can't resolve './definitions' in 'PATHTOAPP/client/node_modules/@capacitor-community/file-opener/dist/esm' Did you mean 'definitions.js'? BREAKING CHANGE: The request './definitions' failed to resolve only because it was resolved as fully specified (probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '.mjs' file, or a '.js' file where the package.json contains '"type": "module"'). The extension in the request is mandatory for it to be fully specified. Add the extension to the request.

    It does work when I edit the file ./node_modules/@capacitor-community/file-opener/dist/esm/index.js line 3 to read:

    export * from './definitions.js'.

    But, can't have the entire team editing files in node_modules.

    bug 
    opened by pkaplan2524 10
  • Gradle build failed: cannot access ContentProvider

    Gradle build failed: cannot access ContentProvider

    Describe the bug Gradle build fails with the following error message:

    /Users/sander/Fork/pomona-app/node_modules/@capacitor-community/file-opener/android/src/main/java/com/ryltsov/alex/plugins/file/opener/FileOpenerProvider.java:6: error: cannot access ContentProvider
    public class FileOpenerProvider extends androidx.core.content.FileProvider {}
           ^
      class file for android.content.ContentProvider not found
    

    To Reproduce Steps to reproduce the behavior:

    1. npm install @capacitor-community/file-opener inside a capacitor v3 project
    2. npx cap sync android
    3. Make Capacitor build
    4. Open Android Studio and try to build app on a simulator (Pixel 5 API 32)

    Expected behavior I expect there to be no gradle errors when building the app with this plugin

    Desktop (please complete the following information):

    • OS: MacOs Mopnterey 12.4

    Smartphone (please complete the following information):

    • Device: Pixel 5
    • API: 32

    Additional context We are using npx jetify for androidX compatibility of some of our used dependencies

    gradle.properties:

    # Project-wide Gradle settings.
    
    # IDE (e.g. Android Studio) users:
    # Gradle settings configured through the IDE *will override*
    # any settings specified in this file.
    
    # For more details on how to configure your build environment visit
    # http://www.gradle.org/docs/current/userguide/build_environment.html
    
    # Specifies the JVM arguments used for the daemon process.
    # The setting is particularly useful for tweaking memory settings.
    org.gradle.jvmargs=-Xmx1536m
    
    # When configured, Gradle will run in incubating parallel mode.
    # This option should only be used with decoupled projects. More details, visit
    # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
    # org.gradle.parallel=true
    
    # AndroidX package structure to make it clearer which packages are bundled with the
    # Android operating system, and which are packaged with your app's APK
    # https://developer.android.com/topic/libraries/support-library/androidx-rn
    android.useAndroidX=true
    # Automatically convert third-party libraries to use AndroidX
    android.enableJetifier=true
    
    org.gradle.java.home=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
    
    export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/Contents/Home
    

    variables.gradle:

    ext {
        minSdkVersion = 22
        compileSdkVersion = 30
        targetSdkVersion = 30
        androidxActivityVersion = '1.2.0'
        androidxAppCompatVersion = '1.2.0'
        androidxCoordinatorLayoutVersion = '1.1.0'
        androidxCoreVersion = '1.3.2'
        androidxFragmentVersion = '1.3.0'
        junitVersion = '4.13.1'
        androidxJunitVersion = '1.1.2'
        androidxEspressoCoreVersion = '3.3.0'
        cordovaAndroidVersion = '7.0.0'
    }
    

    build.gradle:

    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    
    buildscript {
    
        repositories {
            google()
            jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.1.3'
            classpath 'com.google.gms:google-services:4.3.10'
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    apply from: "variables.gradle"
    
    allprojects {
        repositories {
            google()
            jcenter()
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }
    

    app/build.gradle:

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation("androidx.appcompat:appcompat:$androidxAppCompatVersion") {
            force = true
        }
        implementation project(':capacitor-android')
        implementation 'androidx.webkit:webkit:1.4.0'
        testImplementation "junit:junit:$junitVersion"
        androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
        androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
        implementation project(':capacitor-cordova-android-plugins')
        // Import the BoM for the Firebase platform
        implementation platform('com.google.firebase:firebase-bom:28.4.2')
        // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
        // When using the BoM, you don't specify versions in Firebase library dependencies
        // implementation 'com.google.firebase:firebase-messaging'
        implementation 'com.google.firebase:firebase-analytics'
        implementation "com.google.firebase:firebase-iid"
    }
    
    bug wontfix 
    opened by sanderschnydrig 10
  • Support Node 14

    Support Node 14

    Hello, first up, thanks for the great work on this plugin, it's great and works like a charm!

    Is your feature request related to a problem? Please describe. We currently cannot move to Node 16 in our work project and need to stay with Node 14. However, that means, we cannot use this plugin. I have tried to use the plugin with Node 14, everything seems to work fine. So, is there a specific reason, why this plugin requires Node >= 16?

    Describe the solution you'd like Setting the engines.node field in the package.json to >=14 😊

    Describe alternatives you've considered We have obviously considered moving to Node 16 right now. But it's just not possible.

    Additional context EDIT: We are using yarn as our package manager. One can still install the dependencies by using yarn install --ignore-engines. However, that feels hacky.

    Thank you for considering. And if there are specific reasons why Node >=16 is required, please let me know!

    opened by BoveFabio 4
  • Error opening file {

    Error opening file {"code":"UNIMPLEMENTED"}

    Am using the following code: let pdfOutput = url; const directory = File.tempDirectory; File.writeFile(directory, filename, pdfOutput, true).then(success => { FileOpener.showOpenWithDialog(directory + filename, 'application/pdf') .then(() => console.log('File opened')) .catch(e => console.log('Error opening file', e)); }, err => { console.log(" writing File error : ", err) })

    And am getting the error within XCode when trying to download the file (hosted on firebase) ...

    invalid wontfix 
    opened by pmosedale 3
  • Installation/build issue with 1.0.2

    Installation/build issue with 1.0.2

    Describe the bug Installation of 1.0.2 fails due to type: "module" in package.json. Possibly related to the use of typescript in a nextjs project.

    To Reproduce See reproducer at https://github.com/arendjantetteroo/capacitor-file-opener-bug Steps to reproduce are in the readme

    Expected behavior Can be used as 1.0.1 was.

    Screenshots

    Desktop (please complete the following information):

    • OS: Ubuntu
    • Browser all
    • Version

    Smartphone (please complete the following information): N/A

    Additional context Add any other context about the problem here.

    bug priority 
    opened by arendjantetteroo 3
  • Node engine restriction, but why?

    Node engine restriction, but why?

    Hi. Is there a specific reason why the node engine is restricted? I'm using node 18 and it is working fine, but the warning bugs me :)

    npm WARN EBADENGINE Unsupported engine { npm WARN EBADENGINE package: '@capacitor-community/[email protected]', npm WARN EBADENGINE required: { node: '>=16.15.0 <17.0', npm: '>=8.10.0 <9.0' }, npm WARN EBADENGINE current: { node: 'v18.7.0', npm: '8.15.0' } npm WARN EBADENGINE }

    enhancement 
    opened by de-dan 3
  • This package should replace pwlin/cordova-plugin-file-opener2

    This package should replace pwlin/cordova-plugin-file-opener2

    The ionic page https://ionicframework.com/docs/native/file-opener points to a repo that has seen no update in 2 years, and the maintainer also has zero activity since December 2021

    Therefore capacitor-community/file-opener should replace it on the Ionic pages.

    invalid 
    opened by arnotixe 2
  • Android 10 Not able to open files

    Android 10 Not able to open files

    Describe the bug On android 10 only, i am not able to open the files it always fails to open file , as i see in log cat it says

    9.415 7372-7372/ E/Capacitor/FilesystemPlugin: Not able to create 'DOCUMENTS'!

    To Reproduce Steps to reproduce the behavior:

    1. Just click on open document
    2. it ask for the file permission
    3. gives error 9.415 7372-7372/ E/Capacitor/FilesystemPlugin: Not able to create 'DOCUMENTS'!

    Expected behavior Should be able to open the file.

    Screenshots image

    Smartphone (please complete the following information):

    • Device: Any device with android 10
    • OS: Android
    • Browser [e.g. stock browser, safari]
    • Version 10
    wontfix 
    opened by aditbharadwaj 2
  • ShareSheet do not open on iPad when openWithDefault: false

    ShareSheet do not open on iPad when openWithDefault: false

    The bug If I set the openWithDefault option to false to open a file with an application program (e.g. *.docx with Word), the ShareSheet does not open or is not visible on the iPad (tested on iOS 15.5). But it works on the iPhone.

    System):

    • iPadOS 15.5
    • ionic App
    • Capcitor 3

    Smartphone (please complete the following information):

    • iPad 9th Generation

    Solution I changed the following line (74) in the FileOpenerPlugin.swift file

    let rect = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height);
    

    to

    let rect = CGRect(x: 0, y: 0, width: view.frame.width, height: 0);
    

    I hope it helps if someone encounters this problem

    bug 
    opened by hydrococcous 2
  • Capacitor sync fails: no compatible versions found for pod CapacitorCommunityFileOpener

    Capacitor sync fails: no compatible versions found for pod CapacitorCommunityFileOpener

    Describe the bug Capacitor sync cannot find a compatible version for pod "CapacitorCommunityFileOpener"

    To Reproduce Steps to reproduce the behavior:

    1. npm install @capacitor-community/file-opener
    2. npx cap sync

    Expected behavior I expected the Capacitor sync to throw no errors after installing this plugin.

    Screenshots Screenshot 2022-10-19 at 11 28 06

    Desktop (please complete the following information):

    • OS: MacOS Monterey 12.4

    Additional information We would really like to keep our minimum deployment target for out application as it is the default for our Capacitor v3 app and was set when we created the Capacitor v3 app.

    Everywhere in our project.pbxproj: IPHONEOS_DEPLOYMENT_TARGET = 12.0; Looks like the version set in the podspec is s.ios.deployment_target = '13.0'

    We don't need this plugin for iOS at the moment so is there a way to only use it for Android?

    wontfix 
    opened by sanderschnydrig 2
  • When will the package be released?

    When will the package be released?

    Describe the bug This package is what I have been looking for. When I tried installing it, I noticed that it has not been released yet.

    Any idea when this plugin will be released?

    To Reproduce Steps to reproduce the behavior:

    1. npm install @capacitor-community/file-opener

    Expected behavior Download en install the package

    chore 
    opened by FreekMencke 2
Releases(v1.0.4)
Owner
Capacitor Community
The Capacitor Community org contains plugins, tools, and other projects that are driven by the community of Capacitor developers and maintainers.
Capacitor Community
An Xcode Plugin to upload code snippets directly into Slack and Gist

XCSnippetr Share code snippets to Slack and Gist without leaving Xcode ever again! ?? Features Upload code snippets using Slack's and Github's APIs. T

Ignacio Romero Zurbuchen 100 Nov 29, 2022
Xcode Plugin helps you find missing methods in your class header, protocols, and super class, also makes fast inserting.

FastStub-Xcode Life is short, why waste it on meaningless typing? What is it? A code generating feature borrowed from Android Studio. FastStub automat

mrpeak 509 Jun 29, 2022
SwiftLint Plugin for Xcode.

SwiftLint Xcode Plugin Demo Usage Set SwiftLint Path default: Default path is /usr/local/bin/swiftlint relative: Relative path with the current projec

null 18 Jul 23, 2022
PhoneGap / Cordova Social Sharing plugin

PhoneGap / Cordova Social Sharing plugin Every now and then kind folks ask me how they can give me all their money. So if you want to contribute to my

null 0 Oct 21, 2021
A apple search ads attribution plugin for flutter

A apple search ads attribution plugin for flutter

liam 0 Oct 27, 2021
Cordova iOS plugin for Fingerprint SDK.

FingerprintPlugin This is a cordova plugin for Fingerprint SDK. Installation Add Cordova plugin to your project: To add a Cordova plugin to your proje

Khawar Shahzad 0 Nov 19, 2021
A plugin to allow Lightroom to export HEIC files

LRExportHEIC A plugin to allow Lightroom to export HEIC files. There are two components: The plugin itself, which is the component that interfaces wit

Manu Wallner 21 Jan 3, 2023
Joplin - an open source note taking and to-do application with synchronization capabilities for Windows, macOS, Linux, Android and iOS. Forum: https://discourse.joplinapp.org/

Joplin® is a free, open source note taking and to-do application, which can handle a large number of notes organised into notebooks. The notes are sea

Laurent 33.7k Dec 30, 2022
Free and open source manga reader for iOS and iPadOS.

Aidoku A free and open source manga reading application for iOS and iPadOS. Features Ad free Robust WASM source system Online reading through external

null 421 Jan 2, 2023
A free and open source xkcd comic reader for iOS.

A free, ad-free, open-source, native, and universal xkcd.com reader for iOS. Download it from the app store now! Architecture AFNetworking for network

Mike 249 Dec 12, 2022
Start your next Open-Source Swift Framework 📦

SwiftKit enables you to easily generate a cross platform Swift Framework from your command line. It is the best way to start your next Open-Source Swi

Sven Tiigi 821 Dec 28, 2022
Open-source jailbreaking tool for many iOS devices

Open-source jailbreaking tool for many iOS devices *Read disclaimer before using this software. checkm8 permanent unpatchable bootrom exploit for hund

null 0 Nov 6, 2021
Collaborative List of Open-Source iOS Apps

Open-Source iOS Apps A collaborative list of open-source iOS, iPadOS, watchOS and tvOS apps, your contribution is welcome ?? Jump to Apple TV Apple Wa

null 33k Dec 30, 2022
Open-source implementation of Apple's Combine for processing values over time

CombineX 简体中文 Open-source implementation of Apple's Combine for processing values over time. Though CombineX have implemented all the Combine interfac

Luo Xiu 1 Dec 30, 2021
Beam: the open source Reddit client for iOS

Beam for Reddit An open source Reddit client for iOS. Introduction Hi, we're Awkward. In 2014, we started working on a Reddit client called Beam. In t

awkward 250 Dec 30, 2022
Open source Clips-inspired app.

AlohaGIF Website Funny moments? Want to share it as a GIF, but you are worried that you will lose speech from video? Aloha will scan sound and attach

Mike Pyrka 61 Sep 16, 2022
Set `Open using Rosetta` option on Xcode easily

xcode-arch A utility to switch running architecture of Xcode on M1 mac. Motivation Currently, there is no way to toggle Open using Rosetta option othe

Takuhiro Muta 7 Aug 8, 2022
Asset Catalog Viewer allows you to browse and export renditions in an asset catalog (.car) file.

Asset Catalog Viewer With the Asset Catalog Viewer Mac app, you can browse and export various type of renditions in an asset catalog. Features Browse

Joey 16 Jan 1, 2023
The starting file for the 360iDev "It's Widget Time" workshop.

360iDevWidgets_start The starting file for the 360iDev "It's Widget Time" workshop. Syllabus This is a workshop to introduce you to adding widgets to

Steve Lipton 5 Dec 29, 2021