New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
??? Direct access to Android API #12
Comments
@Rpc(description = "Get Memory Statistics By Type")
public float getMemoryStat(@RpcParameter(name = "type") String type) throws InterruptedException {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
long availableMegs = mi.availMem / 1048576L; // returns percentages
long percentAvail = mi.availMem / mi.totalMem; // returns percentages
if (type == "avail") {
return mi.availMem;
} else {
return mi.totalMem;
}
} Untested, but something like this should work... Depends on how you want your returns. |
Thanks for your suggestion. But I mean the title of this issue is more generally to call any API from SL4A, |
i get it now. i'll look into this. off the top of my head i am thinking custom class loading might be the answer. i am not too familiar with it but we can create a SL4A method that accepts the file path to the dex file (dalvik converts class files to dex), as well as any parameters, and returns the data. the only problem is not knowing what the method is going to return (int, string, etc) so it might be tricky creating the method without knowing this.... See this: http://developer.android.com/reference/dalvik/system/DexClassLoader.html |
this is rudimentary since it is only returning as strings right now and has virtually no error handling but I think this is probably the approach to take for this feature. in essence, you can write up a small java class to run any type of methods against the whole android api, compile to dex, store the jar/apk file on your phone and call its methods from this in sl4a. you provide the file path, full class name, method you want, and any arguments...
converting jar to dex: (dx is in android sdk) ./dx --dex --output = output.jar input.jar |
from py4a: kuri65536/python-for-android#87
Is it possible?
The text was updated successfully, but these errors were encountered: