Examples are as follows:
Private Context Motherappscontext=null;
private static final String mcube_package= "COM.MCUBE.ACC";
private static final String mcube_class= "Com.mcube.acc.SensorControl";
Private Class Mcubeclass=null;
Private Integer Initcheck;
Try
{
Motherappscontext = Createpackagecontext (mcube_package,context.context_ignore_security| Context_include_code);
Mcubeclass = Motherappscontext.getclassloader (). LoadClass (Mcube_class);
Final Object myinstance = Mcubeclass.newinstance ();
Final Method getproduct = Mcubeclass.getmethod ("GetProduct", (class[]) null);
Final Method Initjni = Mcubeclass.getmethod ("Init_jni", (class[]) null);
initcheck= (Integer) Initjni.invoke (myinstance);
if (Initcheck! = null && initcheck.intvalue () = = 0)
{
Product = (Integer) getproduct.invoke (myinstance);
if (product! = NULL)
{
LOG.I (TAG, "Get Product ID Check result=" + product.intvalue ());
if (Product.intvalue ()! = 0)
{
if (Mgsensorcali! = null)
Root.removepreference (Mgsensorcali);
LOG.I (TAG, "not mCube product");
}
Else
{
LOG.I (TAG, "MCube product detected");
}
}
}
Else
{
if (Mgsensorcali! = null)
Root.removepreference (Mgsensorcali);
LOG.I (TAG, "product check fail");
}
}
catch (Namenotfoundexception e)
{
E.printstacktrace ();
}
catch (ClassNotFoundException e)
{
E.printstacktrace ();
}
catch (Instantiationexception e)
{
E.printstacktrace ();
}
catch (Illegalaccessexception e)
{
E.printstacktrace ();
}
catch (Nosuchmethodexception e)
{
E.printstacktrace ();
}
catch (InvocationTargetException e)
{
E.printstacktrace ();
}
Android uses the approach provided by the context to implement Java mapping