How to open a file located in a non-sdcard directory in Tasker?


Question

How can one open a file located in a subfolder of the rootfolder, using tasker, in LineageOS 14.1?



My attempts so far have been to:




  1. Create a new task in tasker.

  2. Check if tasker has root permission with variable named "root available": %ROOT. This returns yes. Therefore, I assume Tasker has root permission.

  3. create the action: "open file"

  4. This only allows the accessing the /storage/ of either the internal or external drive.

  5. Therefore, I manually entered the path to the file located in the rootfolder I am trying to access as: /data/misc/wifi/wpa_supplicant.conf and ran the task, but it returns the error: file not found.



    IMG:
    IMG:


  6. So I tried /data/misc/wifi/wpa_supplicant.conf and ran the task, but it returns the same error.


  7. I tried to open the file with fdroid's app: editor, without opening a file explorer to open the file. But I am unable to pass the file location as an argument to the app editor when I create a task to do it.


Answer

The inbuilt Open File action doesn't seem to work for non-/storage file paths because it is hardcoded (I presumed from its error logs) to only load a file located under /storage/emulated/0. Even if you mention the absolute location using file://, it would still append /storage/emulated/0 to the file path and throw an error.



Because Open File action simply sends an intent, we can do that manually ourselves. The Send Intent action is pretty good for this, except it also fails with non-/sdcard file paths. Tasker implements FileProvider (a way to securely share files with other apps). The action could work but Tasker's manifest file provisions for not exporting the file provider, which means other apps cannot make use of it. Since Tasker converts even absolute file path (with file://) into a file provider URI, there is no way out for us to load a non-/sdcard file using that action too, except to ask Tasker's developer to fix this, or the user themselves tweaks the manifest file.



The solution, however, is available using command-line. Use the action:



Code → Run Shell:




  • Command:



    am start -a android.intent.action.VIEW -d "file://FILE_PATH" -t "text/plain" -f 0x13000000 -n android/com.android.internal.app.ResolverActivity


    file:// is intended as is. In your case, the file path should be file:///data/misc/wifi/wpa_supplicant.conf.



    text/plain can be replaced with text/* too if you don't know your file's mime-type.



    (You can know about am here.) I don't know what that flag (0x13000000) does in particular.


  • tick Use Root



Running the task would now give you the bottom sheet with all the apps which can load a file with mime-type text/plain. However, when testing this, only QuickEdit app was able to load that file successfully, so I recommend using it unless you get this working with an another editor.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes