public class Main extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
}
@SuppressWarnings("unused")
private void sayHello(String msg){
Log.d("mmtag",msg);
}
}
package com.example.dexclassloaderserver;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;
import dalvik.system.DexClassLoader;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
useDexClassLoader();
}
@SuppressLint("NewApi")
public void useDexClassLoader() {
Intent mIntent = new Intent();
mIntent.setClassName("com.example.dexclassloaderclient",
"com.example.dexclassloaderclient.MainActivity");
PackageManager pm = this.getPackageManager();
List<ResolveInfo> mList = pm.queryIntentActivities(mIntent,
PackageManager.MATCH_DEFAULT_ONLY);
ResolveInfo info = mList.get(0);
String apkPath = info.activityInfo.applicationInfo.sourceDir;
String optPath = this.getCodeCacheDir().getAbsolutePath();
String libPath = info.activityInfo.applicationInfo.nativeLibraryDir;
DexClassLoader clsLoader = new DexClassLoader(apkPath, optPath,
libPath, this.getClass().getClassLoader());
try {
Class cls = clsLoader
.loadClass("com.example.dexclassloaderclient.MainActivity");
Object obj = cls.newInstance();
Method invokeMethod = cls.getDeclaredMethod("sayHello",
new Class[] { String.class });
invokeMethod.setAccessible(true);
invokeMethod.invoke(obj, "hello world,DexClassLoader");
} catch (Exception e) {
e.printStackTrace();
}
}
}
I/dex2oat (20250): dex2oat took 1.547s (threads: 4) D/mmtag (20229): hello world,DexClassLoader D/OpenGLRenderer(20229): Render dirty regions requested: tru
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有