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

FileDialog SetFilter does not work on Android devices #2353

Closed
alexballas opened this issue Aug 4, 2021 · 8 comments
Closed

FileDialog SetFilter does not work on Android devices #2353

alexballas opened this issue Aug 4, 2021 · 8 comments
Labels
bug Something isn't working

Comments

@alexballas
Copy link
Contributor

Describe the bug:

When I define a file FileDialog Filter like the following
fd.SetFilter(storage.NewExtensionFileFilter([]string{".mp4", ".avi", ".mkv", ".mpeg", ".mov", ".webm", ".m4v", ".mpv"}))
dialog.NewFileOpen does not work on an Android device.
When I remove the filter line, dialog.NewFileOpen will then correctly prompt to select a file manager

Device (please complete the following information):

  • OS: Android
  • Version: 10
  • Go version: 1.16
  • Fyne version: v2.0.3
@alexballas alexballas added the unverified A bug that has been reported but not verified label Aug 4, 2021
@andydotxyz
Copy link
Member

Can you please expand on what "does not work" means?
Does it not appear?
Does it appear without any files?
Does it appear but not allow selection?

@Jacalz
Copy link
Member

Jacalz commented Aug 4, 2021

It would also have been useful with a full code example (like the issue template mentions) to make it easier to reproduce.

@alexballas
Copy link
Contributor Author

alexballas commented Aug 4, 2021

Apologies,

Here is the code in question: https://github.com/alexballas/go2tv/blob/main/internal/gui/gui.go#L197-L236

fd := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
		check(w, err)

		if reader == nil {
			return
		}
		defer reader.Close()

		vfile := reader.URI().Path()
		absVideoFile, err := filepath.Abs(vfile)
		check(w, err)

		videoFileURLencoded := &url.URL{Path: filepath.Base(absVideoFile)}
		screen.VideoText.Text = filepath.Base(vfile)
		screen.videofile = filestruct{
			abs:        absVideoFile,
			urlEncoded: videoFileURLencoded.String(),
		}

		if !screen.CustomSubsCheck.Checked {
			selectSubs(absVideoFile, screen)
		}

		// Remember the last file location.
		screen.currentvfolder = filepath.Dir(absVideoFile)

		screen.VideoText.Refresh()
	}, w)

	fd.SetFilter(storage.NewExtensionFileFilter(screen.videoFormats))

	if screen.currentvfolder != "" {
		vfileURI := storage.NewFileURI(screen.currentvfolder)
		vfileLister, err := storage.ListerForURI(vfileURI)
		check(w, err)
		fd.SetLocation(vfileLister)
	}

	fd.Resize(fyne.NewSize(w.Canvas().Size().Width*1.4, w.Canvas().Size().Height*1.6))
	fd.Show()

When fd.SetFilter(storage.NewExtensionFileFilter(screen.videoFormats)) is there, and I click on the "Select Video File" button (that triggers the code above), nothing happens.

If I completely remove it and recompile it and click again the same button I correctly get Image here

Please let me know if you'd like more info

@Jacalz
Copy link
Member

Jacalz commented Aug 4, 2021

Can you please try to put together a "short and concise" example code? We prefer small example codes (not snippets out of big projects) which makes it much easier to replicate.

@alexballas
Copy link
Contributor Author

Can you please use this standalone example?

package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/dialog"
	"fyne.io/fyne/v2/storage"
	"fyne.io/fyne/v2/widget"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Test Android File Dialog")

	content := widget.NewButton("Open File Dialog", func() {
		go videoAction(myWindow)
	})
	myWindow.SetContent(content)
	myWindow.ShowAndRun()

}

func videoAction(w fyne.Window) {
	fd := dialog.NewFileOpen(func(reader fyne.URIReadCloser, err error) {
		fmt.Println(reader)
	}, w)

	fd.SetFilter(storage.NewExtensionFileFilter([]string{".mp4", ".avi", ".mkv", ".mpeg", ".mov", ".webm", ".m4v", ".mpv"}))
	fd.Show()
}

You can replicate the issue by commenting out the fd.SetFilter line.

@Jacalz
Copy link
Member

Jacalz commented Aug 4, 2021

Thanks. That example code is more than good enough in my opinion :)

@andydotxyz andydotxyz added bug Something isn't working and removed unverified A bug that has been reported but not verified labels Aug 11, 2021
@andydotxyz andydotxyz added this to the Aberlour (2.1) milestone Aug 11, 2021
@andydotxyz
Copy link
Member

From logcat I get this:

08-11 16:58:21.435 21547 21547 E ChooserActivity: Failed to get target intent filter
08-11 16:58:21.435 21547 21547 E ChooserActivity: android.content.IntentFilter$MalformedMimeTypeException: 
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.content.IntentFilter.processMimeType(IntentFilter.java:902)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.content.IntentFilter.addDataType(IntentFilter.java:840)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.content.IntentFilter.<init>(IntentFilter.java:460)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.app.ChooserActivity.getTargetIntentFilter(ChooserActivity.java:2893)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.app.ChooserActivity.queryDirectShareTargets(ChooserActivity.java:2957)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.app.ChooserActivity.onListRebuilt(ChooserActivity.java:3923)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.app.ResolverActivity.onPostListReady(ResolverActivity.java:1287)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.app.ResolverListAdapter$2.run(ResolverListAdapter.java:478)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.os.Handler.handleCallback(Handler.java:938)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.os.Looper.loop(Looper.java:246)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at android.app.ActivityThread.main(ActivityThread.java:8512)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at java.lang.reflect.Method.invoke(Native Method)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
08-11 16:58:21.435 21547 21547 E ChooserActivity: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

@andydotxyz
Copy link
Member

The issue was that more than one unknown file type would generate an invalid mime type list.
This is now fixed so the file picker appears.
Unfortunately the android picker uses mime and the file mime from extension lookup is pretty poor - so a list like yours will probably just result in the / mime list - but that is a different issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants