UnityNativeFilePicker icon indicating copy to clipboard operation
UnityNativeFilePicker copied to clipboard

Android app, "No apps can perform this action" error

Open LunXyy opened this issue 1 year ago • 23 comments

Hello, I have an issue when trying to pick files. It works in editor and in build on my computer, it also works with unity remote. When I Try to build it and a phone, even If the application have the rights to access the files (I also looked at the android manifest), the message "No apps can perform this action" appears. I tried on Bluestacks, Xiaomi, Huawei but still the same error. I saw some post, saying that it's because I have no application to pick the files, but since I'm using one (UnityNativeFilePicker isn't an app, but it should handle this I think) I don't really understand the problem, I have no compilation errors or anything, also the message appears before any folder/ file get displayed.

Sorry if my English is bad, I hope someone has a solution

LunXyy avatar Jul 19 '23 18:07 LunXyy

Hi, can I see your code?

yasirkula avatar Jul 20 '23 13:07 yasirkula

using System.Collections; using System.IO; using UnityEngine; using UnityEngine.UI;

public class FilePickerSystem : MonoBehaviour {

public string finalPath;


public static FilePickerSystem instance;

private void Awake()
{
    if(instance != null)
    {
        Debug.LogWarning("Il y a plus d'une instance FilePickerSystem dans la scène");
        return;
    }

    instance = this;
}

private void Start()
{
    Debug.Log(NativeFilePicker.CheckPermission(false));
    NativeFilePicker.RequestPermission(false);
    NativeFilePicker.OpenSettings();
}



public string LoadFile()
{
    string fileType = NativeFilePicker.ConvertExtensionToFileType("wav,aiff,pcm,flac,alac,wma,mp3,ogg,aac,au,mid,midi,");
    finalPath = null;
    NativeFilePicker.Permission permission = NativeFilePicker.PickFile((path) =>
    {
       if (path == null)
       {
       Debug.Log("operation cancelled");
       }
       else
       {
        finalPath = path;
        Debug.Log("Picked file : " + finalPath);
       }
    }, new string[] {fileType});
    return finalPath;
}

}

LunXyy avatar Jul 21 '23 10:07 LunXyy

I also have this in another script, I know the WWW class is outdated, but it seems like there wasn't any problem

public IEnumerator LoadSound(string name, string _path) { WWW request = GetAudioFromFile(_path, name); yield return request; AudioClip audioClip = request.GetAudioClip(); audioClip.name = name; buttons.Last().button.GetComponent<AudioSource>().clip = audioClip; }

public WWW GetAudioFromFile(string path, string filename)
{
    WWW request = new WWW(path);
    return request;
}

LunXyy avatar Jul 21 '23 10:07 LunXyy

ConvertExtensionToFileType accepts a single extension. You can call it as many times as you wish, one call per extension.

yasirkula avatar Jul 21 '23 14:07 yasirkula

changed it string fileType = NativeFilePicker.ConvertExtensionToFileType("mp3"); but still the same problem, still work in editor but not in build

LunXyy avatar Jul 24 '23 17:07 LunXyy

I wish I knew why, it just should've worked 😞

yasirkula avatar Jul 24 '23 19:07 yasirkula

have the same problem. Using a samsung although i think that doesnt matter.

using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using UnityEngine.UI;

public class filePickerSystem : MonoBehaviour {

public string FinalPath;

public Image ima;

public void LoadFile()
{
    string FileType = NativeFilePicker.ConvertExtensionToFileType("*");
    NativeFilePicker.Permission permission = NativeFilePicker.PickFile((path) =>
    {
        if (path == null)
        {

        }
        else
        {
            FinalPath = path;
            Sprite sprite = Sprite.Create(LoadPNG(FinalPath), new Rect(0, 0, 400, 400), new Vector2(0.5f, 0.0f), 1.0f);
            ima.sprite = sprite;
        }
    }, new string[] { FileType });
    
}

public void SaveFile()
{
    string filePath = Path.Combine(Application.temporaryCachePath, "test.txt");
    File.WriteAllText(filePath, "Hello world!");
    NativeFilePicker.Permission permission = NativeFilePicker.ExportFile(filePath, (success) => Debug.Log("file exported: " + success));
    
}
public static Texture2D LoadPNG(string filePath)
{

    Texture2D tex = null;
    byte[] fileData;

    if (File.Exists(filePath))
    {
        fileData = File.ReadAllBytes(filePath);
        tex = new Texture2D(2, 2);
        tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
    }
    return tex;
}

} i get the following message Screenshot_20230801_122954_Android System

NIKOLAOS77 avatar Aug 01 '23 09:08 NIKOLAOS77

@NIKOLAOS77 ConvertExtensionToFileType accepts only a valid extension. You can pass "*/*" directly to PickFile (without passing it to ConvertExtensionToFileType) to achieve the desired effect on Android.

yasirkula avatar Aug 02 '23 09:08 yasirkula

It seems like you can directly use "audio/*" on PickFile method and being able to select audio files.

Nischal-012 avatar Aug 07 '23 08:08 Nischal-012

@NIKOLAOS77 ConvertExtensionToFileType accepts only a valid extension. You can pass "*/*" directly to PickFile (without passing it to ConvertExtensionToFileType) to achieve the desired effect on Android.

I'm using

{
	NativeFilePicker.Permission permission = NativeFilePicker.PickFile((path) =>
	{
		if (path == null)
			Debug.Log("Operation cancelled");
		else
			Debug.Log("Picked file: " + path);
	}, new string[] { ".png" });

	Debug.Log("Permission result: " + permission);
}

The code directly from the repository instructions, but it's not working. Same error, "No apps can perform this action". I've tried replacing the string array with a single string and it gets the same issue. I'm not even using ConvertExtensionToFileType.

Mashimaro7 avatar Dec 14 '23 21:12 Mashimaro7

You can't pass an extension directly to PickFile. You must pass it to ConvertExtensionToFileType. "*/*" isn't an extension but rather a MIME type which is why it can't be passed to ConvertExtensionToFileType.

yasirkula avatar Dec 15 '23 07:12 yasirkula

You can't pass an extension directly to PickFile. You must pass it to ConvertExtensionToFileType. "*/*" isn't an extension but rather a MIME type which is why it can't be passed to ConvertExtensionToFileType.

oh, okay. I was able to get it working without any extensions, but i tried this

{
	string fileType = NativeFilePicker.ConvertExtensionToFileType("/image");
	NativeFilePicker.Permission permission = NativeFilePicker.PickFile((path) =>
	{
		if (path == null)
			Debug.Log("Operation cancelled");
		else
			Debug.Log("Picked file: " + path);
	}, fileType);

	Debug.Log("Permission result: " + permission);
}

And it had the same issue.

Mashimaro7 avatar Dec 15 '23 18:12 Mashimaro7

"/image" isn't an extension so you shouldn't pass it to ConvertExtensionToFileType 😸 Here's the golden rule: if we are talking about an actual file extension (e.g. png), pass it to ConvertExtensionToFileType. If we're talking about a MIME type (e.g. image/*), don't pass it to ConvertExtensionToFileType (note that passing MIME types like that won't work on iOS since iOS uses UTIs instead of MIME types).

yasirkula avatar Dec 15 '23 20:12 yasirkula

I'm still getting the same issue. No apps to perform this action. Device Tested : Google Pixel 6a

private string[] allowedImageTypes = { "png"};
private void OnImageSelectionClicked()
        {
            NativeFilePicker.PickFile(OnModelPicked, allowedImageTypes);
        }

prakyath-07 avatar Jan 07 '24 19:01 prakyath-07

@prakyath-07 Try this: NativeFilePicker.PickFile(OnModelPicked, NativeFilePicker.ConvertExtensionToFileType("png"));

yasirkula avatar Jan 07 '24 21:01 yasirkula

@yasirkula Thanks for the reply. this works, but not able to pick fbx files, Getting same warning "No apps can perform this action"

prakyath-07 avatar Jan 11 '24 15:01 prakyath-07

@prakyath-07 FBX doesn't have a MIME type as far as I can see. You could try NativeFilePicker.PickFile(OnModelPicked, "application/octet-stream") on Android and when the user selects a file, verify that its extension is fbx (selection won't be limited to fbx).

yasirkula avatar Jan 11 '24 15:01 yasirkula

Thanks :) this works only on Android, any alternative for iOS?

prakyath-07 avatar Jan 28 '24 09:01 prakyath-07

NativeFilePicker.PickFile(OnModelPicked, NativeFilePicker.ConvertExtensionToFileType("png"));

How do I allow user to select video or image (png, jpeg, mp4)?

prakyath-07 avatar Jan 28 '24 09:01 prakyath-07

Any updates?

prakyath-07 avatar Jan 29 '24 10:01 prakyath-07

@prakyath-07 To be able to pick all files: https://forum.unity.com/threads/native-file-picker-for-android-ios-open-source.912890/page-3#post-8987518 (or you could limit the selection to FBX files on iOS by declaring a custom file type via Window-NativeFilePicker Custom Types on iOS). You can also pass multiple file types to PickFile function since it takes a string array.

yasirkula avatar Jan 29 '24 14:01 yasirkula

image

still not able to select media file with multiple formats

prakyath-07 avatar Jan 29 '24 16:01 prakyath-07

NativeFilePicker.PickFile(OnMediaFilePicked, NativeFilePicker.ConvertExtensionToFileType("png"), NativeFilePicker.ConvertExtensionToFileType("jpeg"), NativeFilePicker.ConvertExtensionToFileType("mp4"));

yasirkula avatar Jan 29 '24 20:01 yasirkula