开发者

Android Assets without context

开发者 https://www.devze.com 2023-03-18 09:14 出处:网络
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 ge

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 t开发者_运维知识库he 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


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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消