1

I create the following class:

public class GlobalVariables
{
    public static string databasePath = FilesDir.Path;
    private GlobalVariables()
    {
    }
}

But FilesDir.Path is underlined with red and it doesn't allow me to import its namespaces to use it. When I use it in some Activity I'm able to but when I'm trying to use it in a class like that I'm not able to. With that class I'm trying to get the apk folder path of the project.

York Shen
  • 9,014
  • 1
  • 16
  • 40

1 Answers1

1

How to use FilesDir.Path property outside Activity(Xamarin.Android)?

You need using a Context to implement this feature:

public class GlobalVariables  
{
    public static string databasePath = Android.App.Application.Context.FilesDir.Path;
    ...
}

Furthermore, you could refer to: What is 'Context' on Android?

York Shen
  • 9,014
  • 1
  • 16
  • 40