Android怎样用代码实现安装apk到/system/app
2016-05-28
展开全部
手机要ROOT,然后用下面的代码试试
package com.sfer.install;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
public class InstallActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String paramString= "$ adb push MySMS.apk /sdcard/" +"\n"+
"$ adb shell" +"\n"+
"$ su" +"\n"+
"# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system" +"\n"+
"# cat /sdcard/MySMS.apk > /system/app/MySMS.apk" +"\n"+
"# mount -o remount,ro -t yaffs2 /dev/block/mtdblock3 /system" +"\n"+
"# exit" +"\n"+
"$ exit";
if(RootCmd.haveRoot()){
if(RootCmd.execRootCmdSilent(paramString)==-1){
Toast.makeText(this, "安装不成功", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(this, "安装成功", Toast.LENGTH_LONG).show();
}
}else{
Toast.makeText(this, "没有<a href="https://www.baidu.com/s?wd=root%E6%9D%83%E9%99%90&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1dhnhnzn103Pvw9PHnYnjK-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHTsPj6kP1R3PW61PWTLP1D3n0" target="_blank" class="baidu-highlight">root权限</a>", Toast.LENGTH_LONG).show();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询