plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

Tauri dialog box not opening in Android 15

Open xksteven opened this issue 9 months ago • 5 comments

I was trying to test this out on a phyisical Android 15 device. Logs read by running adb logcat. I can test on other virtual devices if desired.

Main error is here: No Activity found to handle Intent { act=android.intent.action.PICK typ=application/*...

Which seems to indicate that the plugin needs to optionally use a different intent such as new Intent(Intent.ACTION_OPEN_DOCUMENT);

I'm not that familiar with the tauri plugin codebase otherwise I'd make the change myself.

Longer logs to give more context.

02-13 17:39:13.966  5761  5761 I GoogleInputMethodService: GoogleInputMethodService.onStartInput():1568 onStartInput(EditorInfo{EditorInfo{packageName=com.read_anywhere.app, inputType=0, inputTypeString=NULL, enableLearning=false, autoCorrection=false, autoComplete=false, imeOptions=12000000, privateImeOptions=null, actionName=UNSPECIFIED, actionLabel=null, initialSelStart=-1, initialSelEnd=-1, initialCapsMode=0, label=null, fieldId=0, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false)
02-13 17:39:13.966  5761  5761 I Module  : DeviceLockedStatusModuleProvider$Module.updateDeviceLockedStatus():100 repeatCheckTimes = 1, locked = false
02-13 17:39:13.967  1722  1759 W PackageConfigPersister: App-specific configuration not found for packageName: com.read_anywhere.app and userId: 0
02-13 17:39:13.967  5761  5761 I AndroidIME: InputBundleManager.loadActiveInputBundleId():407 loadActiveInputBundleId: und-Latn-x-password, password
02-13 17:39:13.969 15059 15059 V Tauri/Plugin: Tauri plugin: pluginId: dialog, command: showFilePicker
02-13 17:39:13.972 15059 15071 I ad_anywhere.app: Background concurrent mark compact GC freed 10019KB AllocSpace bytes, 26(2248KB) LOS objects, 84% free, 4567KB/28MB, paused 189us,1.650ms total 113.834ms
02-13 17:39:13.981 15059 15073 W ad_anywhere.app: ApkAssets: Deleting an ApkAssets object '<empty> and /data/app/~~02vgaGieu_dJGP8ldaa57A==/com.google.android.webview--2CRQaFaUX48UJZyESyd0w==/base.apk' with 2 weak references
02-13 17:39:14.024  1722  1759 I ActivityTaskManager: START u0 {act=android.intent.action.PICK typ=application/* (has extras)} with LAUNCH_MULTIPLE from uid 10050 result code=-91
02-13 17:39:14.024 15059 15059 E Tauri   : No Activity found to handle Intent { act=android.intent.action.PICK typ=application/* (has extras) }

xksteven avatar Feb 14 '25 20:02 xksteven

i tested it less than a week ago for https://github.com/tauri-apps/plugins-workspace/pull/2410 and didn't see any issues 🤔 Can you share your code and the output of tauri info? And if you wouldn't mind, testing another (virtual) device would indeed be appreciated :)

FabianLars avatar Feb 14 '25 20:02 FabianLars

I'll see if I can get a minimal version of the code. The codebase has gotten semi big but can trim it to be MVP to reproduce the bug.

npm run tauri info

> [email protected] tauri
> tauri info


[✔] Environment
    - OS: Ubuntu 24.4.0 x86_64 (X64)
    ✔ webkit2gtk-4.1: 2.46.5
    ✔ rsvg2: 2.58.0
    ✔ rustc: 1.84.0 (9fc6b4312 2025-01-07)
    ✔ cargo: 1.84.0 (66221abde 2024-11-19)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-unknown-linux-gnu (default)
    - node: 18.19.1
    - npm: 9.2.0

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.2
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.1.1 (outdated, latest: 2.2.0)
    - @tauri-apps/cli : 2.1.0 (outdated, latest: 2.2.7)

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : 2.2.0
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : 2.2.0

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: ../build
    - devUrl: http://localhost:1420/
    - framework: Svelte
    - bundler: Vite

xksteven avatar Feb 14 '25 21:02 xksteven

@FabianLars Here's a "minimal" example where I can successfully open a file on linux or mac but not on Android and experiences the bug above. The minimal example reproduces the error for me. I still haven't tried on a debugger. I don't recall how to test that with tauri atm.

https://github.com/xksteven/tauri_android_bug/tree/main

I stripped down the app so it doesn't really do anything other than try to open a file.

Relevant file location where I open a dialog box

Let me know if there's anything else I need to provide to help out.

xksteven avatar Feb 15 '25 01:02 xksteven

No Activity found to handle Intent means that there is no app that can be called. So may not be viable for some devices.

This appears to be due to the following code

fun showFilePicker(invoke: Invoke)

var intent = if (parsedTypes.isNotEmpty()) {
    val intent = Intent(Intent.ACTION_PICK)
        setIntentMimeTypes(intent, parsedTypes)
        intent
    } else {
        val intent = Intent(Intent.ACTION_GET_CONTENT)
        intent.addCategory(Intent.CATEGORY_OPENABLE)
        intent.type = "*/*"
        intent
    }
}

We need to use Intent.ACTION_OPEN_DOCUMENT, which opens the system's file picker app, instead of Intent.ACTION_PICK. Or add a process for when the intent is not available as follows

// If the intent is not available, use system's file picker app instead
if (intent.resolveActivity(activity.packageManager) == null) {
    val i = Intent(Intent.ACTION_OPEN_DOCUMENT)
    i.addCategory(Intent.CATEGORY_OPENABLE)
    setIntentMimeTypes(i, parsedTypes) 

    intent = i
}

aiueo13 avatar Feb 17 '25 05:02 aiueo13

Same here in Android 8 (real device) and Android 12 (emulator). adb logcat shows:

03-05 20:31:49.805 27436 27436 I Timeline: Timeline: Activity_launch_request time:187536342 intent:Intent { act=android.intent.action.PICK typ=application/* (has extras) }
03-05 20:31:49.808  1203  2919 W ActivityManager: aInfo is null
03-05 20:31:49.808  1203  2919 W com.android.server.am.ExtraActivityManagerService: Intent or aInfo is null!
03-05 20:31:49.809  1203  2919 I ActivityManager: START u0 {act=android.intent.action.PICK typ=application/* (has extras)} from uid 10445

tauri info:

[✔] Environment
    - OS: Mac OS 15.3.0 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.83.0 (90b35a623 2024-11-26)
    ✔ cargo: 1.83.0 (5ffbef321 2024-10-29)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.9.0
    - pnpm: 10.4.1
    - yarn: 1.22.22
    - npm: 10.9.1

[-] Packages
    - tauri 🦀: 2.2.5
    - tauri-build 🦀: 2.0.5
    - wry 🦀: 0.48.1
    - tao 🦀: 0.31.1
    - @tauri-apps/api : 2.2.0
    - @tauri-apps/cli : 2.2.7 (outdated, latest: 2.3.1)

[-] Plugins
    - tauri-plugin-deep-link 🦀: 2.2.0
    - @tauri-apps/plugin-deep-link : 2.2.0
    - tauri-plugin-process 🦀: 2.2.0
    - @tauri-apps/plugin-process : 2.2.0
    - tauri-plugin-shell 🦀: 2.2.0
    - @tauri-apps/plugin-shell : 2.2.0
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : 2.2.0
    - tauri-plugin-log 🦀: 2.2.1
    - @tauri-apps/plugin-log : 2.2.1 (outdated, latest: 2.2.3)
    - tauri-plugin-haptics 🦀: 2.2.3
    - @tauri-apps/plugin-haptics : 2.2.3
    - tauri-plugin-updater 🦀: 2.4.0
    - @tauri-apps/plugin-updater : 2.4.0 (outdated, latest: 2.5.1)
    - tauri-plugin-window-state 🦀: 2.2.1
    - @tauri-apps/plugin-window-state : not installed!
    - tauri-plugin-os 🦀: 2.2.0
    - @tauri-apps/plugin-os : 2.2.0
    - tauri-plugin-cli 🦀: 2.2.0
    - @tauri-apps/plugin-cli : 2.2.0
    - tauri-plugin-single-instance 🦀: 2.2.1
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-http 🦀: 2.3.0
    - @tauri-apps/plugin-http : 2.3.0
    - tauri-plugin-opener 🦀: 2.2.5
    - @tauri-apps/plugin-opener : 2.2.5 (outdated, latest: 2.2.6)
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : 2.2.0

[-] App
    - build-type: bundle
    - CSP: default-src 'self' 'unsafe-inline' blob: data: customprotocol: asset: http://asset.localhost ipc: http://ipc.localhost; connect-src 'self' blob: data: asset: http://asset.localhost ipc: http://ipc.localhost https://*.sentry.io https://*.posthog.com https://*.deepl.com https://*.wikipedia.org https://*.wiktionary.org https://*.supabase.co https://*.readest.com wss://speech.platform.bing.com https://*.cloudflarestorage.com; font-src 'self' blob: data: asset: http://asset.localhost tauri: https://fonts.gstatic.com https://db.onlinewebfonts.com https://cdn.jsdelivr.net; frame-src 'self' blob: asset: http://asset.localhost; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: asset: http://asset.localhost https://*.sentry.io https://*.posthog.com; img-src 'self' blob: data: asset: http://asset.localhost https://*; style-src 'self' 'unsafe-inline' blob: asset: http://asset.localhost https://cdn.jsdelivr.net https://fonts.googleapis.com
    - frontendDist: ../out
    - devUrl: http://localhost:3000/
    - framework: React (Next.js)
    - bundler: Webpack

chrox avatar Mar 05 '25 13:03 chrox

I think I am having this same issue on both a physical device and an emulator. I made a minimal reproduction:

https://gitlab.com/lastOf/minimal-filepicker-tauri

logcat excerpt:

                                                            com.epub_reader_minimal_repro.app    V  Tauri plugin: pluginId: dialog, command: showFilePicker

2025-07-21 16:09:47.375  4775-4775  Tauri                   com.epub_reader_minimal_repro.app    E  No Activity found to handle Intent { act=android.intent.action.PICK typ=application/epub+zip xflg=0x4 (has extras) }

2025-07-21 16:09:47.378  1515-1515  GoogleInputMethodService com.google.android.inputmethod.latin  I  GoogleInputMethodService.onStartInput():1293 onStartInput(EditorInfo{EditorInfo{packageName=com.epub_reader_minimal_repro.app, inputType=0, inputTypeString=NULL, enableLearning=false, autoCorrection=false, autoComplete=false, imeOptions=12000000, privateImeOptions=null, actionName=UNSPECIFIED, actionLabel=null, initialSelStart=-1, initialSelEnd=-1, initialCapsMode=0, label=null, fieldId=0, fieldName=null, extras=null, hintText=null, hintLocales=[]}}, false)

2025-07-21 16:09:47.379   693-932   PackageConfigPersister  system_server                        W  App-specific configuration not found for packageName: com.epub_reader_minimal_repro.app and userId: 0

Am I understanding the thread correctly that the filepicker just isnt working on android? If so, what workarounds are available?

Lastofthefirst avatar Jul 22 '25 14:07 Lastofthefirst

It works now on Android but you need to pay attention to the parameters passed to dialog open. See example: https://github.com/readest/readest/blob/main/apps/readest-app/src/services/nativeAppService.ts#L255-L261

chrox avatar Jul 22 '25 14:07 chrox

Ok, @chrox what issues are there in my call, it looks good to me:

import { createSignal } from "solid-js";
import { open } from '@tauri-apps/plugin-dialog';
import { readFile } from '@tauri-apps/plugin-fs';
import { invoke } from "@tauri-apps/api/core";
import "./App.css";

function App() {
  const [bookContent, setBookContent] = createSignal([]);

  async function selectBook() {
    const selected = await open({
      multiple: false,
      filters: [{
        name: 'Epub',
        extensions: ['epub']
      }]
    });

    if (selected) {
      try {
        const fileData = await readFile(selected);
        const contents = await invoke("read_book", { data: fileData });
        setBookContent(contents);
      } catch (error) {
        console.error("Failed to read book:", error);
        // Optionally, display an error message to the user
      }
    }
  }

  return (
    <main class="container">
      <h1>Ebook Reader</h1>

      <button onClick={selectBook}>Select Book</button>

      <div class="ebook-content">
        {bookContent().map((chapter, index) => (
          <div key={index} innerHTML={chapter} />
        ))}
      </div>
    </main>
  );
}

export default App;


Lastofthefirst avatar Jul 22 '25 15:07 Lastofthefirst

You simply cannot use the extensions params. See https://github.com/readest/readest/blob/main/apps/readest-app/src/app/library/page.tsx#L438-L449

chrox avatar Jul 23 '25 13:07 chrox

Hello friends, https://github.com/tauri-apps/plugins-workspace/pull/2866 made me suspicious so i finally investigated it myself as well and came up with https://github.com/tauri-apps/plugins-workspace/pull/2871. I expect it to be merged and released quickly but if not you can test it by adding this to your cargo.toml file.

[patch.crates-io]
tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "fix/dialog/android-filters" }

FabianLars avatar Jul 24 '25 15:07 FabianLars

Hello friends, #2866 made me suspicious so i finally investigated it myself as well and came up with #2871. I expect it to be merged and released quickly but if not you can test it by adding this to your cargo.toml file.

[patch.crates-io] tauri-plugin-dialog = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "fix/dialog/android-filters" }

@FabianLars It works on my Android 8 and Android 13 devices and now I can filter files by extensions. Thanks for your great work.

chrox avatar Jul 25 '25 12:07 chrox

thanks for testing it!

FabianLars avatar Jul 25 '25 13:07 FabianLars