当前位置: 编程技术>移动开发
本页文章导读:
▪起用另一个程序某些方法 启用另一个程序某些方法
DexFile df = new DexFile(new File("/data/app/my_downloaded_lib.apk")); ClassLoader cl = getClassLoader(); Class clazz = df.loadClass("com/my/lib/MyClass", cl);
2.cl = new DexClassLoader("/full/path/com.example.apk.........
▪ 设立GPS状态 设置GPS状态
很久没写博客了,人懒事多,没有办法,言归正传,今天就说下设置GPS状态吧。很久以前就看过android源码,它是这样设置GPS状态的:private void setGpsState(Context context, boolean state).........
▪ 卸载程序跟监听卸载事件 卸载程序和监听卸载事件
package com.TestUI;
import java.util.List;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.view.View;
import an.........
[1]起用另一个程序某些方法
来源: 互联网 发布时间: 2014-02-18
启用另一个程序某些方法
DexFile df = new DexFile(new File("/data/app/my_downloaded_lib.apk"));
ClassLoader cl = getClassLoader();
Class clazz = df.loadClass("com/my/lib/MyClass", cl);
2.cl = new DexClassLoader("/full/path/com.example.apk",
getFilesDir().getAbsolutePath(),// /data/data/foo/files
null, // native lib path, I haven't used this
MyClass.class.getClassLoader());
// This doesn't make Class.forName() work, instead I do this:
Class<?> foo = cl.loadClass("com.example.foo");
3.
PathClassLoader("/data/app/org.startsmall.myapp.apk",
ClassLoader.getSystemClassLoader());
final String apkFiles =
"/data/app/org.startsmall.myapp.apk:" + // myself
// handlers defined by other developers
"/data/app/" + handlerClassName.substring(0, lastDotPos) + ".apk";
dalvik.system.PathClassLoader myClassLoader =
new dalvik.system.PathClassLoader(
apkFiles,
ClassLoader.getSystemClassLoader());
// ...
try {
Class<?> handler =
Class.forName(handlerClassName, true, classLoader);
// Call reflective APIs.
} catch (ClassNotFoundException e) {
// .....
[2] 设立GPS状态
来源: 互联网 发布时间: 2014-02-18
设置GPS状态
很久没写博客了,人懒事多,没有办法,言归正传,今天就说下设置GPS状态吧。
很久以前就看过android源码,它是这样设置GPS状态的:
可是,在android 2.2以前的版本中,Google并没有给我们的SDK开放这个函数,如果你的工程中用到它,只能到源码环境下去能编。还好,android 2.2中已经开放了这个函数。
Google经常以安全为由,在SDK中关闭了很多API,开发者只能到源码环境下去调用它。我真的很怀疑,难道这样就安全了吗?仅仅是在门口加了个台阶而已。
很久没写博客了,人懒事多,没有办法,言归正传,今天就说下设置GPS状态吧。
很久以前就看过android源码,它是这样设置GPS状态的:
private void setGpsState(Context context, boolean state) {
ContentResolver resolver = context.getContentResolver();
Settings.Secure.setLocationProviderEnabled(resolver, LocationManager.GPS_PROVIDER, state);
}可是,在android 2.2以前的版本中,Google并没有给我们的SDK开放这个函数,如果你的工程中用到它,只能到源码环境下去能编。还好,android 2.2中已经开放了这个函数。
Google经常以安全为由,在SDK中关闭了很多API,开发者只能到源码环境下去调用它。我真的很怀疑,难道这样就安全了吗?仅仅是在门口加了个台阶而已。
[3] 卸载程序跟监听卸载事件
来源: 互联网 发布时间: 2014-02-18
卸载程序和监听卸载事件
package com.TestUI;
import java.util.List;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.LightingColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
public class TestUI extends Activity implements OnClickListener{
/** Called when the activity is first created. */
private Button button;
public mDeleteReceiver mDelete;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView) findViewById(R.id.textview);
button=(Button)findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent delete = new Intent(Intent.ACTION_DELETE,Uri.parse("package:com.et.TextScroll"));
startActivity(delete);
}
});
}
public class mDeleteReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Toast.makeText(context, "卸载", Toast.LENGTH_LONG).show();
Log.i("11111", "22222222222");
}
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_DATA_CLEARED);
filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
filter.addDataScheme("package");
mDelete = new mDeleteReceiver();
registerReceiver(mDelete, filter);
super.onResume();
}
/***不能在onPause()注销这个广播,因为跳转到卸载画面时这个activity是pause状态**/
@Override
protected void onPause() {
// TODO Auto-generated method stub
//unregisterReceiver(mDelete);
super.onPause();
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
unregisterReceiver(mDelete);
super.onDestroy();
}
}
最新技术文章: