Skip to content

Commit

Permalink
[floatingball]Try to send shell cmd,but still has error.
Browse files Browse the repository at this point in the history
  • Loading branch information
monsterLang committed Oct 12, 2021
1 parent c1d2e7b commit 51f25ce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1849,13 +1849,27 @@
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.Date;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;





public class MainActivity extends AppCompatActivity {

private static final String TAG_MAIN = "MainActivity";
Expand Down Expand Up @@ -1940,6 +1954,8 @@ public class MainActivity extends AppCompatActivity {
private Button btn_shellcmd;
private String cmd_sendshell;
private EditText edittext_shellcmd;
Runtime runtime;
Process proc;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -2058,7 +2074,21 @@ public void onClick(View arg0) {
else
{
// send shell cmd
// ShellCmd a = new ShellCmd(cmd_sendshell);
runtime = Runtime.getRuntime();
try {
proc = runtime.exec(cmd_sendshell);
// is = proc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), "gbk"));
String line = null;
while ((line = reader.readLine()) != null){
System.out.println(line);
}
}
catch (Exception e){
e.printStackTrace();

}

}

Expand All @@ -2073,6 +2103,7 @@ public void onClick(View arg0) {
// code from
//https://www.cnblogs.com/tianzhijiexian/p/3994546.html
private class FloatingListener implements View.OnTouchListener {
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public boolean onTouch(View arg0, MotionEvent event) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.example.demo_v7_addshell;

import android.content.Context;
import android.widget.Toast;

import java.lang.Runtime;
import java.lang.Process;
import java.io.IOException;
Expand All @@ -24,8 +26,14 @@ public ShellCmd(String cmd) throws IOException {
try {
proc = runtime.exec(cmd);
// is = proc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream(), "gbk"));
String line = null;
while ((line = reader.readLine()) != null){
System.out.println(line);
}
}
catch (Exception e){
e.printStackTrace();

}

Expand Down

0 comments on commit 51f25ce

Please sign in to comment.