7

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

Clement
  • 367
  • 2
  • 18
  • The android.nfc package is part of android.jar, so you should be able to access it. Is it the getSystemService(NFC_SERVICE) call that you are having trouble with? – kenny_k Apr 24 '13 at 07:12

1 Answers1

0

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
Robert Beltran
  • 495
  • 3
  • 9