Extending Adobe AIR

摘译自http://www.adobe.com/devnet/air/articles/extending-air.html




Android details

On Android, two extension models are supported: Java archives for extensions developed with the Android SDK, and shared libraries for those developed with the Native Development Kit (NDK). Both are appropriate for some set of extensions; simply pick the one that best suits your use case. (One can, of course, use JNI to bridge between Java and native code on Android, should that also be necessary.)

Android上支持两种扩展模型:Android SDK开发的Java archives,NDK开发的shared libraries。(也可以通过JNI桥接Java和native code)

On Android, resources such as images are compiled into each application and accessed via constants in the generated class R. This mechanism doesn't support composition; there is only one instance of R available. Android extensions can include resources but, to work around this limitation, they must be accessed via an API provided by the runtime.

在Android上,图片之类的资源被编译到每个程序里,通过R中的constants访问。这种机制不支持composition;只有一个可用的R实例,Android扩展可以包含资源,不过要受这个限制。它们必须通过runtime提供的API访问。

To include resources in your Android extension, first place them in the "res" subdirectory of the Android platform directory, using the same naming conventions and file structure as for a regular Android application. At packaging time, resources from all extensions are merged into the resources directory of the main application. In order to avoid name conflicts, extensions should use a unique prefix for their resources.

为了在你的Android扩展中包含资源,首先把它们直接放在Android platform的res子目录,使用与通常Android程序一样的命名规则和文件结构。打包的时候,所有扩展的资源被合并到主程序的resource目录。为了避免名字冲突,扩展应该为它们的资源使用唯一的前缀。

These resources will be merged, as will the code in the Java archive, into the compiled dex and resources files of the main application. They can then be accessed via the FREContext.getResourceId() method, which takes the desired resource ID as an argument. In other words, instead of accessing an image as, for example, R.drawable.background_image, use getResourceId( "drawable.background_image" ).


Note that this API is available only in Java, as the Android resource mechanism is a Java construct, not expected to be accessed by extensions using native Android development.

The Java FREContext class also provides, on Android only, a getActivity() method that returns the main application Activity, which in turn is required by a variety of Android APIs.



你可能感兴趣的:(java,android,Adobe,resources,extension,Constants)