没有上下文的 Android 资产
关于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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要访问不存在的 Context,您可以扩展 Application 类并创建对 Context 的静态引用。这样您就可以从应用程序中的任何位置访问它:
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: