jar包封装参考

初始化

//通过类加载进行初始化,没有对外暴露,对外只是暴露SystemInf

private SystemInf mInterface = null;

public boolean init(Context ctx) {

if (this.mInterface == null) {

try {

DexClassLoader cls_loader = ClassLoaderHelper.getCalssLoader(ctx);

if (cls_loader == null) {

return false;

}

Class myClass = cls_loader.loadClass("com.entrance.hwinf.SystemDevice");

this.mInterface = (SystemInf)myClass.newInstance();

} catch (Exception var4) {

Log.e("hwinf_SystemAdapter", "load class error: " + var4);

return false;

}

}

return this.mInterface.init(ctx);

}

类怎么加载呢

static DexClassLoader getCalssLoader(Context ctx) {

if (mClassLoader == null) {

File f1 = new File("/system/framework/com.entrance.hwdevice.jar");

File f2 = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/com.entrance.hwdevice.jar");

String dex_path = null;

String tmpPath = ctx.getDir("jar", 0).getAbsolutePath();

if (f1.exists()) {

dex_path = f1.getAbsolutePath();

} else if (f2.exists()) {

dex_path = f2.getAbsolutePath();

}

if (dex_path == null) {

Log.w("hwinf_ClassLoader", "the com.entrance.hwdevice.jar not exist!");

return null;

}

Log.d("hwinf_ClassLoader", "jar url is: " + dex_path);

mClassLoader = new DexClassLoader(dex_path, tmpPath, (String)null, ctx.getClassLoader());

}

return mClassLoader;

}

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值