Unable to find the problem in the extension

Hi,
some months ago I developed an extension to use Firebase and Storage (FirebaseManager Extension)
and I added an sample project to show how it works.
Some days ago I tried the sample and it close when I try to upload a file in the storage.
I tried to debug to understand where there is the exception,
in the past I used to create a log file adding this code:

public void appendLog(String text)
{
File logFile = new File("sdcard/FirebaseManager.txt");
if (!logFile.exists())
{
try
{
logFile.createNewFile();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try
{
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true));
buf.append(text);
buf.newLine();
buf.flush();
buf.close();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

But now this code doesn't work, the log file is not created.
I thought the problem is that there is restriction and I can create a file only in the app folder so I tried this path:
file:///storage/emulated/0/Android/data/appinventor.ai_mpbejo.ShoppingList/files/FirebaseManager.txt
But when I try to read the file always is not found

So I'm stuck I do not how to solve the problem about the log file (that can be useful in the future for other projects) and the extension
Somebody could help me
Thank You
Marco

Is the problem with the file upload, or with the log file, or both ? Does the log file work with any other actions/methods ?

This is unlikely to work on newer versions of Android, depending on the working directory of your app at the time it is called, as Android has put an increasing number of restrictions on where files can be written in the file system and the amount of permission needed to read/write those files.

We provide utility classes such as the FileUtil class and its openForWriting method to open files in the appropriate location depending on SDK level.

2 Likes

Hi @TIMAI2, the problem at this moment is with the log file, because I solved the extension bug. In the future I will use the classes suggested by @ewpatton
Thank You
Best Regards
Marco

1 Like

Hi @ewpatton, thank You, I will use your utility classes in the future for my extensions.
Best Regards
Marco