没有上下文的 Android 资产

发布于 2024-11-19 00:17:05 字数 190 浏览 1 评论 0原文

关于Android资产管理器,是否可以在没有上下文的情况下从资产中获取文件?我读到我可以使用“file:///android_assets”类型的路径初始化一个 File 对象,然后从那里获取文件,但它说该文件不存在(Honeycomb)。

解决此问题的一般解决方法是什么?没有任何方法可以获取我需要资产中的文件的位置的上下文。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情场扛把子 2024-11-26 00:17:06

要访问不存在的 Context,您可以扩展 Application 类并创建对 Context 的静态引用。这样您就可以从应用程序中的任何位置访问它:

public class MyApp extends Application {

    public static Context context;

    @Override
    public void onCreate() {
        super.onCreate();
        context = getApplicationContext();
    }
}

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();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文