UnityNativeFilePicker
UnityNativeFilePicker copied to clipboard
Android app, "No apps can perform this action" error
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
Hi, can I see your code?
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;
}
}
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;
}
ConvertExtensionToFileType accepts a single extension. You can call it as many times as you wish, one call per extension.
changed it string fileType = NativeFilePicker.ConvertExtensionToFileType("mp3"); but still the same problem, still work in editor but not in build
I wish I knew why, it just should've worked 😞
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
@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.
It seems like you can directly use "audio/*" on PickFile method and being able to select audio files.
@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.
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.
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.
"/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).
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 Try this: NativeFilePicker.PickFile(OnModelPicked, NativeFilePicker.ConvertExtensionToFileType("png"));
@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 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).
Thanks :) this works only on Android, any alternative for iOS?
NativeFilePicker.PickFile(OnModelPicked, NativeFilePicker.ConvertExtensionToFileType("png"));
How do I allow user to select video or image (png, jpeg, mp4)?
Any updates?
@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.
still not able to select media file with multiple formats
NativeFilePicker.PickFile(OnMediaFilePicked, NativeFilePicker.ConvertExtensionToFileType("png"), NativeFilePicker.ConvertExtensionToFileType("jpeg"), NativeFilePicker.ConvertExtensionToFileType("mp4"));