下面代码中loadApps 获得所有apk信息,后面代码在gridview中点击某项进入相应的app
66 void loadApps(){
67 Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);
68 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
69 mApp = this.getPackageManager().queryIntentActivities(mainIntent, 0);
70 Log.e("mApp", ""+mApp.size());
71 }
ResolveInfo info = mApp.get(arg2);
84 String pkg = info.activityInfo.packageName;
85 String cls = info.activityInfo.name;
86 ComponentName compoment = new ComponentName(pkg,cls);
87 Intent i = new Intent();
88 i.setComponent(compoment);
89 startActivity(i);
public static boolean rootConmmand(String cmd){
78
79 Process process = null;
80 DataOutputStream os = null;
81
82 try {
// 执行su命令,process.getOutputStream获得子进程的输出流
83 process = Runtime.getRuntime().exec("su");
DataOutputStream允许应用程序以适当方式将基本 Java 数据类型写入输出流中
创建一个新的数据输出流,将数据写入指定基础输出流。
84 os = new DataOutputStream(process.getOutputStream());
85 os.writeBytes(cmd+"\n");
86 os.writeBytes("exit\n");
87 os.flush();
//导致当前线程等待,如有必要,一直要等到由该 Process 对象表示的进程已经终止。
88 process.waitFor();
89
90 } catch (IOException e) {
91 // TODO Auto-generated catch block
92 Log.d("*** DEBUG ***", "ROOT REE" + e.getMessage());
93 e.printStackTrace();
94 } catch (InterruptedException e) {
95 // TODO Auto-generated catch block
96 e.printStackTrace();
97 }finally{
98
99 try {
100 if(os!=null){
101 os.close();
102 }
103 process.destroy();
104 } catch (IOException e) {
105 // TODO Auto-generated catch block
106 e.printStackTrace();
107 }
108 }
109 Log.d("*** DEBUG ***", "Root SUC ");
110 return true;
private void write2System(int src) throws FileNotFoundException{
114
115 ProgressDialog pd = new ProgressDialog(this);
116 pd.show();
//建立输入流后将此输入流拷贝输出到文件输出流中
117 InputStream is = this.getResources().openRawResource(src);
118 OutputStream os = null;
119 File file = new File("/system/media","bootanimation.zip");
120
121 os = new FileOutputStream(file);
122
123
124 byte[] buf = null;
125 int length;
126 try {
127 buf = new byte[1024];
128 while((length=is.read(buf))!=-1){
129 os.write(buf, 0, length);
130 Log.e("写", ""+length);
131
132 }
133 } catch (IOException e) {
134 // TODO Auto-generated catch block
135 e.printStackTrace();
136 }finally{
137 if(is!=null){
138 try {
139 is.close();
140 } catch (IOException e) {
141 // TODO Auto-generated catch block
142 e.printStackTrace();
143 }
144 }
145
146 }
147 rootConmmand("chmod 777 /system/media/bootanimation.zip");
148 Log.e("dfg", "ok");
149 pd.dismiss();
150 Toast.makeText(this, "开机动画安装成功,可重启查看效果", Toast.LENGTH_LONG).show();
151
152 }
153
154 }
执行以下代码即可改变开机动画
String apkRoot="chmod 777 /system/media";
if(rootConmmand(apkRoot)){
rootConmmand("chmod 777 /system/media/bootanimation.zip");
write2System(R.raw.mi);
setTitle("当前开机动画为小米开机动画");