Android 执行SU命令
我正在开发一个应用程序,可以在根设备上设置沉浸式模式,但我无法执行命令,在主活动上,我检查设备是否根,如果根设备是根设备,我开始打开第二个活动,其中我有需要执行命令的按钮:Android 执行SU命令,android,shell,superuser,Android,Shell,Superuser,我正在开发一个应用程序,可以在根设备上设置沉浸式模式,但我无法执行命令,在主活动上,我检查设备是否根,如果根设备是根设备,我开始打开第二个活动,其中我有需要执行命令的按钮: import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Butt
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import eu.chainfire.libsuperuser.Shell;
public class MainActivity extends AppCompatActivity {
Button btnSU;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnSU = findViewById(R.id.bv_checkSu);
btnSU.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
checkSU();
}
});
}
private void checkSU(){
try {
if (Shell.SU.available()) {
Toast.makeText(this, "Congratulation you're SU", Toast.LENGTH_SHORT).show();
Intent i = new Intent(this, setScreenActivity.class);
startActivity(i);
finish();
}else{
Toast.makeText(this,"Sorry No SU shell Found",Toast.LENGTH_SHORT);
}
}catch(Exception e){
e.printStackTrace();
Toast.makeText(this,"Sorry an Error has Occured",Toast.LENGTH_SHORT).show();
}
}
}
设置筛选活动:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class setScreenActivity extends AppCompatActivity {
Button btnFull;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
btnFull = findViewById(R.id.bv_Full);
btnFull.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Immersive im = new Immersive();
im.setImmersiveFull();
}catch(IOException e){
e.printStackTrace();
}
}
});
}
}
在setScreenActivity上,我在按钮上设置了一个监听器,然后它显示了一个“浸入式类对象”,我在其中应用了“setImmersiveFull()方法”
当我在我的真实手机上运行应用程序时,一切都进行得非常顺利,甚至当我点击按钮“满”时,祝酒词会出现,但屏幕根本没有改变,这很奇怪,因为当我在终端模拟器应用程序上运行命令时,屏幕会变为沉浸式模式
下面是沉浸式课程:
import android.content.Context;
import android.widget.Toast;
import java.io.IOException;
public class Immersive {
public Context ctx;
public void setImmersiveFull() throws IOException {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(String[] {"settings put global policy_control immersive.full=apps,-com.google.android.googlequicksearchbox"});
Toast.makeText(ctx,"Full Immersive Mode Set",Toast.LENGTH_SHORT).show();
}
public void setImmersiveNoNavBar() throws IOException{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(String[] {"settings put global policy_control immersive.navigation=apps,-com.google.android.googlequicksearchbox"});
Toast.makeText(ctx,"No Navigation Bar Immersive Mode Set",Toast.LENGTH_SHORT).show();
}
public void setImmersiveNoStatusBar() throws IOException{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(String[] {"settings put global policy_control immersive.status=apps,-com.google.android.googlequicksearchbox"});
Toast.makeText(ctx,"No Status Bar Immersive Mode Set",Toast.LENGTH_SHORT).show();
}
public void setStockMode() throws IOException{
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(String[] {"settings put global policy_control immersive="});
Toast.makeText(ctx,"Stock Mode Set",Toast.LENGTH_SHORT).show();
}
}
我的设备是根设备,运行Android Oreo 8.0.0
有没有关于我应该如何以SU编程方式运行此命令的想法
谢谢您应该调用
Shell.SU.run(“命令”)
而不是使用运行时创建进程