//---code
public void btn_del(View v){
Uri pkgURI = Uri.parse("package:com.sinbon.ddr300.bcast001");
Intent del_itt = new Intent(Intent.ACTION_DELETE, pkgURI);
startActivity ( del_itt );
}
public void btn_ins(View v){
Log.i("-------------", Environment.getExternalStorageDirectory().toString());
String fileName = "/storage/sdcard0/Download/bcast001.apk";
Intent it = new Intent(Intent.ACTION_VIEW);
it.setDataAndType(Uri.parse("file://" + fileName), "application/vnd.android.package-archive");
it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(it);
}
public void btn_run(View v){
String packageName="com.sinbon.ddr300.bcast001";
PackageManager manager = getPackageManager();
try {
Intent i = manager.getLaunchIntentForPackage(packageName);
if (i == null) {
Log.i("-------------","err-1------------------");
return ;
}
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return;
} catch (Exception e) {
Log.i("-------------","err-2------------------");
return;
}
}
//---permission
//----
有platform signature的APK,成為system Apps, 就有root的權限,做一些su才能做的事
//---如何platform signauture
方法之一
把Eclipes做的APK source拷到
BSP\development
加入如下Andriod.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
# Only compile source java files in this apk.
LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := Cat007 <--------------------這個要改 br="">LOCAL_SDK_VERSION := current
LOCAL_CERTIFICATE := platform
#LOCAL_MODULE_TAGS := tests
include $(BUILD_PACKAGE)
# Use the following include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
source, lunch, 再到該目錄下編譯APK
mm -B
再到BSP\
make
生成的system.img就包有該APK,並具有root權限
(所以每一次測試APK都要10 min T_T )
//--- stop apk , 例如代入"com.example.cat002"
public void btn_1(View v) {
EditText et1 = (EditText) findViewById(R.id.editText1);
String pkg = et1.getText().toString();
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
Method forceStopPackage;
try {
forceStopPackage = am.getClass().getDeclaredMethod(
"forceStopPackage", String.class);
forceStopPackage.invoke(am, pkg);
} catch (Exception e) {
}
}
需加permission
//--- install apk silently , 例如代入"com.example.cat002"
public void btn_3(View v) {
EditText et1 = (EditText) findViewById(R.id.editText1);
String pkg = et1.getText().toString();
pkg="pm uninstall "+pkg;
try{
Runtime.getRuntime().exec(pkg );
}catch(Exception e){
}
}
需加permission