Android PersistentDataPath UnauthorizedAccessException
I can't find a good explanation for how to resolve this issue. It seems like certain users are installing my application on their external storage. The PersistentDataPath returned for that is a location in their external storage in which my application does not have Write permissions.
UnauthorizedAccessException: Access to the path "/storage/sdcard1/Android/data/blackjack.allin1.com/files/bj_allin1_data.dat" is denied.
FileStream file;
if (File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "bj_allin1_data.dat"))
{
file = File.Open(Application.persistentDataPath + Path.DirectorySeparatorChar + "bj_allin1_data.dat", FileMode.Open);
}
else
{
file = File.Create(Application.persistentDataPath + Path.DirectorySeparatorChar + "bj_allin1_data.dat");
}
My settings are:
Install location: Prefer External, Write Permission: Internal
Since only a small number of devices install the app on external storage I would rather not ask for permissions to write external. Is there a solution to continue to write internal even if the app is installed external? Alternatively, can I only ask permissions to write external on those devices that install at external storage? What is the proper solution for this issue? Thanks
EDIT: If I change Write Permission to external will this ask all users for permission to access external?
If I change Install Location to Force Internal would this also solve my issue in a way?