Hi, I want to download a PDF-file (or any other file, e.g. *.jpg) in my Android-App and afterwards open it. Seems to be very complicated since API 23 (Thread, solution doesn´t work for me) No matter if I need write permissions / sdcard etc, it would be great to have a working example. Please! Thank you very much!
I want to open the downloaded file from inside my Android Unity-App with a button and a method like Application.OpenUrl().
Anyone get this working? I'm trying to navigate to a PDF located on a website. Like: https://www.google.com/some.pdf but my app crashes when I call Application.OpenUrl(). This is not a local pdf, so FileBrowswer or whatever doesn't apply. Am I missing a permission?
I opened chrome in kiosk mode using command line interface. string chromePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"; string arguments = url+" --kiosk"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(chromePath,arguments); System.Diagnostics.Process.Start(startInfo); Using similar way we can open adobe reader. string adobePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\AcroRD32.exe"; string arguments = url+" <Path of pdf>"; System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(chromePath,arguments); System.Diagnostics.Process.Start(startInfo); // We can add other arguments to specify our query --> //arguments += "other arguments"; //http://www.robvanderwoude.com/commandlineswitches.php#Acrobat
I was looking for same but couldnt find many leads below is my working code to download pdf from given url and store in android path. this code can process any file and can be saved, That file just need to put in exact file format in the name(ex. xyz.pdf or abc.docx). so i used exact name given in url while downloading. Hope It helps. Code (CSharp): IEnumerator SavePdf() { UnityWebRequest request = UnityWebRequest.Get(" Your pdf Url Path here "); yield return request.SendWebRequest(); if (request.isNetworkError || request.isHttpError) { Debug.Log(request.error); } else { string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android",System.StringComparison.Ordinal)); //pdf saving path string savePath = path + "/MyDocs/"; if(!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string[] temp = pdfUrl.Split('/'); string x = Path.Combine(savePath,temp[temp.Length-1]); System.IO.File.WriteAllBytes (x, request.downloadHandler.data); } }
Hi thanks for sharing your code, on the 19th line you put pdfUrl.Split('/') thats a plugin or a library ? or it is native feature?
its a native feature, its basically a String.split which splits data by character eg. if i have file path "android/data/document/abcd.pdf" then that will split it into four different strings to give you array with length 4 where arr[0]=android, arr[1]=data, arr[2]=document, arr[3]=abcd.pdf the last arr[3] is been used so we could save the file with same exact name as it was saved on server