Good afternoon, I am following the steps to create a pdf of these links:
https://www.syncfusion.com/kb/9174/how-to-create-a-pdf-file-in-xamarin
https://help.syncfusion.com/file-formats/pdf/create-pdf-file-in-xamarin
Even in the example project they give, I get the same problem, when pressing the button nothing happens and I see that the method is exited when it passes through the following line:
using System;
using System.IO;
using Android.Content;
using Java.IO;
using Xamarin.Forms;
using System.Threading.Tasks;
[assembly: Dependency(typeof(SaveAndroid))]
class SaveAndroid: ISave
{
//Method to save document as a file in Android and view the saved document
public async Task SaveAndView(string fileName, String contentType, MemoryStream stream)
{
string root = null;
//Get the root path in android device.
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.ExternalStorageDirectory.ToString();
}
else
root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
//Create directory and file
Java.IO.File myDir = new Java.IO.File(root + "/Syncfusion");
myDir.Mkdir();
Java.IO.File file = new Java.IO.File(myDir, fileName);
//Remove if the file exists
if (file.Exists()) file.Delete();
//Write the stream into the file
FileOutputStream outs = new FileOutputStream(file); //AQUI
outs.Write(stream.ToArray());
outs.Flush();
outs.Close();
//Invoke the created file for viewing
if (file.Exists())
{
Android.Net.Uri path = Android.Net.Uri.FromFile(file);
string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString());
string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(path, mimeType);
Forms.Context.StartActivity(Intent.CreateChooser(intent, "Choose App"));
}
}
}
I have already granted you the read and write permissions:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />