Titanium Hyperloop access to android.os.SystemProperties

194 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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.

3
On

It is because android.os.SystemProperties is not class you can import. Check the android documentation at https://developer.android.com/reference/android/os/package-summary.html

You could use

var build = require('android.os.Build');
console.log(build.SERIAL);

to access the serial number.