I've been recently exploring how to access Android's Libraries via JRuby in SL4A. I know it is possible to design apps with Ruboto, but I just want to right a simple script to access APIs that current SL4A doesn't offer. I can import normal jars and such but I haven't been able to get Android's API. In specific I want to access 'android.nfc'. Is there a way do accomplish this that I haven't figured out yet or is it possible to not work; SL4A does state that JRuby offers a direct API bridge though.
Thanks, Clement
Can you include your Jruby code? Are you building your classpath properly and then doing the java_import as well?
I have a ruby file just for loading up my jars into my classpath that I require in every .rb file called java_jars.rb it contains the following:
Dir["target/dependency/\*.jar"].each { |jar| require jar }
then in the main ruby file do this:
include Java
require 'java_jars'
java_import 'com.package.name.blah.ApiClassName'
def methodName
apiObject = com.package.name.blah.ApiClassName.new
# don't forget methodName becomes method_name in JRuby
apiObject.method_name
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.