'How to add saving file dialog in the Android app (Unity3d)

I want the user to be able to save the previously created .csv file to the device or send it to mail or messenger. I've already done it in Android Studio (Java) like this:

try{
    //saving the file into the device
    FileOutputStream out = openFileOutput("shafa.csv", Context.MODE_PRIVATE);

    Locale current = getResources().getConfiguration().locale;
    if(current.getLanguage().equals("uk") || current.getLanguage().equals("ru")){
        out.write((shafa.toString()).getBytes("Cp1251"));
    }else{
        out.write((shafa.toString()).getBytes());
    }
    out.close();

    //exporting
    Context context = getApplicationContext();
    File filelocation = new File(getFilesDir(), "shafa.csv");
    Uri path = FileProvider.getUriForFile(context, "com.dev.app.fileprovider", filelocation);
    Intent fileIntent = new Intent(Intent.ACTION_SEND);
    fileIntent.setType("text/csv");
    fileIntent.putExtra(Intent.EXTRA_SUBJECT, "Shafa");
    fileIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    fileIntent.putExtra(Intent.EXTRA_STREAM, path);
    startActivity(Intent.createChooser(fileIntent, "Send mail"));
    }
    catch(Exception e){
        e.printStackTrace();
    }

I'm remaking this project in Unity and I want the functionality to be the same. I've found how to save it to the app folder, but it's not enough

private string fileName = Application.persistentDataPath + "/specification.csv";

public void WriteCSV() {
    StringBuilder shafa = new StringBuilder();
    shafa.Append("sep=,");
    shafa.Append("\n" + LocalizationManager.GetTranslate("calculationOptions") + "," + " ");
    //...
    shafa.Append("\n" + LocalizationManager.GetTranslate("warning") + "," + " ");

    TextWriter tw = new StreamWriter(fileName, false);
    tw.WriteLine(shafa.ToString());
    tw.Close();
}

I will be glad for any advice, thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source