accessing static fields from different application
I have a bad feeling about this question but...
Given this class
class A {
public static final String field = "I_m_a_field";
}
in the package com.uselessoftware.A and compiled as A.apk.
Is it possible to read the static field from a different application in a different package? Lets suppose (all pseudo):
class B {
void readField() {
iDontKnow obj = loadExternalClass("com.uselessoftware.A", "A");
String externalField = obj.readStaticAsString(obj, "field");
}
}
in开发者_如何学编程 the package com.uselessoftware.B and compiled as B.apk.
Context _external_context = createPackageContext("com.uselessoftware.A", context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY);
Class<?> _external_class = _external_context.getClassLoader().loadClass("com.uselessoftware.A");
Field _external_field = _external_class.getField("field");
String _field = (String) _external_field.get(null);
is not due to me, found this discussion googling.
精彩评论