UnityNativeFilePicker icon indicating copy to clipboard operation
UnityNativeFilePicker copied to clipboard

Working on simulator but not on Device

Open nataliapoppe9 opened this issue 1 year ago • 2 comments

Description of the bug

Im using your example code and its working amazing on the simulator, but when I build it on my Device no image is shown. It asks for permision and I give permission. I access my galley and choose a picture. ( Meanwhile a message is shown saying I will only be able to access the chosen images. When I choose one and select Add. A loading window appears for a milisec, but no image is shown.

The code;

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

public class FilePickerSystem : MonoBehaviour { private string myFileType; string myPath; private Sprite mySprite; public GameObject imagen;

void Start()
{
	myFileType = NativeFilePicker.ConvertExtensionToFileType("jpg");
	Debug.Log("pdf's MIME/UTI is: " + myFileType);
}

void Update()
{
	if (Input.GetMouseButtonDown(0))
	{
		// Don't attempt to import/export files if the file picker is already open
		if (NativeFilePicker.IsFilePickerBusy())
			return;

		if (Input.touchCount > 0)
		{
			
			NativeFilePicker.Permission permission = NativeFilePicker.PickFile((path) =>
			{
				if (path == null)
					Debug.Log("Operation cancelled");
				else
					Debug.Log("Android Picked file: " + path);
				myPath = path;
					StartCoroutine( ChangeImage());

			}, new string[] { myFileType });

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



IEnumerator ChangeImage()
{
	WWW www = new WWW(myPath);
	while (!www.isDone)
	{
		Debug.Log("null");
		yield return 0;
	}

	Debug.Log(www.text);
	mySprite = Sprite.Create(www.texture, new Rect(0.0f, 0.0f, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f), 100.0f);
	imagen.GetComponent<Image>().sprite = mySprite;
}

}

  • Unity version: 2021.3.0f1*
  • Platform: . Android
  • Device: XIAOMI Redmi Note 11
  • Android Version: 11 RKQ1.211001.001
  • How did you download the plugin: GitHub, 4 days ago - Latest version

nataliapoppe9 avatar Dec 14 '23 00:12 nataliapoppe9

I already Changed Player Settings to Write permission SD Card

nataliapoppe9 avatar Dec 14 '23 00:12 nataliapoppe9

Can you try WWW www = new WWW("file://" + myPath);? Also I'd strongly recommend NativeGallery instead.

yasirkula avatar Dec 14 '23 06:12 yasirkula