Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Assets without context

regarding the Android Assets manager, is it possible to get a file from the assets without context? I read that I can initialize a File object with "file:///android_assets" kind of path, and then get the file from there, but it says that the file does not exist (Honeycomb).

What is the general workaround around this issue? There is no any way to get the context on the place I need the files from the assets.

Thanks

like image 840
Pett Avatar asked Jul 07 '11 07:07

Pett


1 Answers

To get access to the Context where it's not present you can extend Application class and create the static reference to the Context. This way you can access it from anywhere within the application:

public class MyApp extends Application {

    public static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
    }
}
like image 191
Alexey A. Avatar answered Sep 20 '22 14:09

Alexey A.