load jar file of class dynamically
来源:互联网 发布:java重用 编辑:程序博客网 时间:2024/06/07 05:12
package com.example.sposedtest;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import dalvik.system.DexClassLoader;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// de.robv.android.xposed.XposedBridge.
load_class();
}
});
Button btn2 = (Button) findViewById(R.id.Button2);
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// de.robv.android.xposed.XposedBridge.
click_button();
}
});
}
private static native void click_button();
private void load_class() {
final File optimizedDexPath = getDir("dex", Context.MODE_PRIVATE);
Log.d("DEXLOADER", " dexInternalStoragePath.exists = "
+ optimizedDexPath.toString());
Log.d("DEXLOADER", " dexInternalStoragePath.exists = "
+ optimizedDexPath.exists());
if (!optimizedDexPath.exists()) {
try {
optimizedDexPath.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
DexClassLoader loader = new DexClassLoader("/data/MainActivity.jar",
optimizedDexPath.getAbsolutePath(), null, getClassLoader());
Class<?> clazz;
try {
clazz = loader.loadClass("com.example.test.MainActivity");
Object obj = clazz.newInstance();
Method m = clazz.getMethod("sayHello");
m.invoke(obj);
Log.d("DEXLOADER", "m = " + m);
} catch ( Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
// TODO Auto-generated catch block
}
// dog.sayHello();
}
public void sayHello() {
Log.d("DEXLOADER", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>helloooooooooooooooooooooo ");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
- load jar file of class dynamically
- Load javascript file dynamically
- framework_intermediates/classes.jar: unknown package name of class file
- Applied Reflection: Dynamically accessing properties of a class at runtime
- How to delete the log file of log4j dynamically
- Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file 2010-08-03
- 严重:Unable to load bean: type: class:com.opensymphony.xwork2.ObjectFactory - bean - jar:file:/E:/Tomc
- Create class type dynamically
- The Jar of this class file belongs to container 'Android Dependencies' which does not allow modifica
- websphere load class order by xml file
- load all plugin sample dynamically.
- eclipse 第三方jar包 关联源码,提示 The Jar of this class file belongs to container 'Android Dependencies'
- eclipse 第三方jar包 关联源码,提示 The Jar of this class file belongs to container 'Android Dependencies'
- dynamically load more items to the ListView
- The JAR of this class file belongs to container 'Android Private Libraries' Android查看外部依赖jar的源码问题解
- Failed to load Main-Class manifest attribute from logTjOutputUtil.jar
- update manifest.mf of a jar file
- The structure of a class file
- 方程求根的几种数值方法--求解x^3 - x -1 = 0
- javascript事件(2)
- 完美逆向百度手机助手5.0底部菜单栏 - Android Tabhost 点击动画
- 500多位商界领袖聚首《移动互联网与金融领袖峰会》5月23-25日.广州站 财智赢未来!
- EF调用存储过程无法返回复杂类型,提示所选存储过程或函数未返回任何列
- load jar file of class dynamically
- 循环单链表的实现方式(C++版)
- eclipse修改所有背景颜色
- VC++常见BUG防范与解决方法
- DEDECMS做好安全防护,8步法!
- DOM 方法实现java 读取xml文件
- 如何选择核雕放大镜
- MFC 对话框最小到系统托盘
- string和int互相转化