是否可以在 Android 库项目中获取应用程序的上下文? [英] Is it possible to get application's context in an Android Library Project?
问题描述
我想获取在运行时在我的库项目的一个类中引用/托管我的库的应用程序的上下文.是否可以?如果是,如何?
I would like to get the context of application which has reference/hosted my library at run-time inside one class of my library project. Is it possible? If yes, how?
谢谢
更新我不希望我的用户将参数中的上下文传递给我的库项目,因为我的库项目可能会通过 JNI 调用,我不知道如何在 JNI 中获取上下文并将其传递给 Java 层.>
Update I don't want my user to pass context in parameter to my library project because it is possible that my library project will be called through JNI and I have no idea how I can get context in JNI and pass it to Java layer.
推荐答案
有可能吗?
是的.
如果是,如何?
将其作为参数传入.
我不希望我的用户将参数中的上下文传递给我的库项目,因为我的库项目可能会通过 JNI 调用,我不知道如何在 JNI 中获取上下文并将其传递给 Java 层.
I don't want my user to pass context in parameter to my library project because it is possible that my library project will be called through JNI and I have no idea how I can get context in JNI and pass it to Java layer.
然后弄清楚[你]如何在 JNI 中获取上下文并将其传递给 Java 层".我想你会像任何其他对象一样传递它.正如@Blundell 所指出的,您实际上没有任何其他选择.
Then figure out "how [you] can get context in JNI and pass it to Java layer". I would imagine that you would pass it like any other object. As @Blundell noted, you do not really have any other option.
这篇关于是否可以在 Android 库项目中获取应用程序的上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!