androidtitaniumappceleratorappcelerator-hyperloop

Titanium Hyperloop access to android.os.SystemProperties


I have been trying a ( i hope) simple bit of Android hyperloop code directly within a titanium project (using SDK 7.0.1.GA and hyperloop 3).

var sysProp = require('android.os.SystemProperties');
var serialNumber = sysProp.get("sys.serialnumber", "none");

But when the app is run it reports

Requested module not found:android.os.SystemProperties

I think this maybe due to the fact that when compiling the app (using the cli) it reports

hyperloop:generateSources: Skipping Hyperloop wrapper generation, no usage found ...

I have similar code in a jar and if I use this then it does work, so I am wondering why the hyperloop generation is not being triggered, as I assume that is the issue.

Sorry should have explained better.

This is the jar source that I use, the extraction of the serial number was just an example (I need access to other info manufacturer specific data as well), I wanted to see if I could replicate the JAR functionality using just hyperloop rather that including the JAR file. Guess if it's not broke don't fix it, but was curious to see if it could be done.


Solution

  • So with the feedback from @miga and a bit of trial and error, I have come up with a solution that works really well and will do the method reflection that is required. My new Hyperloop function is

    function getData(data){
    
        var result = false;
        var Class = require("java.lang.Class");
        var String = require("java.lang.String");
    
        var c = Class.forName("android.os.SystemProperties");
        var get = c.getMethod("get", String.class, String.class);
        result = get.invoke(c, data, "Error");
        return result;
    
    }
    

    Where data is a string of the system property I want.

    I am using it to extract and match a serial number from a Samsung device that is a System Property call "ril.serialnumber" or "sys.serialnumber". Now I can use the above function to do what I was using the JAR file for. Just thought I'd share in case anyone else needed something similar.