切换风格

默认Lavender Sky Flowers Wizard Snow Beige California City Dragon Black London Sunset glow Pink Cloud

6

主题

120

积分

0

精华

用户组 

易积分
164
热心
0
好评
0
E4A 的核心类库JAR包[复制链接]
发表于 2020-8-17 01:16:40 | 显示全部楼层 |阅读模式
E4A 的核心类库JAR包 需要的拿去使用
图片上次不了 就不上传了  
下面是系统权限操作代码
package com.e4a.runtime;
游客,如果您要查看本帖隐藏内容请回复

import com.e4a.runtime.annotations.SimpleFunction;
import com.e4a.runtime.annotations.SimpleObject;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


@SimpleObject
public final class Root权限操作
{
  private static boolean haveRoot = false;
  private static DataInputStream inputStream;
  private static DataOutputStream outputStream;
  private static Process process;
  private static BufferedReader reader;

  @SimpleFunction
  public static boolean 手机是否已Root() {
    if (haveRoot == true) {
      return true;
    }
    i = 执行命令行("echo test");
    if (i != -1) {
      haveRoot = true;
    } else {
      haveRoot = false;
    }
    return haveRoot;
  }

  @SimpleFunction
  public static String 执行命令行2(String cmd) {
    String str1 = "";
    try {
      process = Runtime.getRuntime().exec("su");
      outputStream = new DataOutputStream(process.getOutputStream());
      inputStream = new DataInputStream(process.getInputStream());
      isreader = new InputStreamReader(inputStream);
      reader = new BufferedReader(isreader);
      byte[] data1 = (cmd + "\n").getBytes();
      outputStream.write(data1);
      outputStream.flush();
      byte[] data2 = "exit\n".getBytes();
      outputStream.write(data2);
      outputStream.flush();
      String str2 = null;
      while ((str2 = reader.readLine()) != null) {
        if (!str1.equals("")) {
          str1 = str1 + "\n" + str2; continue;
        }
        str1 = str2;
      }

      process.waitFor();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (outputStream != null) {
        try {
          outputStream.close();
        } catch (IOException e2) {
          e2.printStackTrace();
        }
      }
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e3) {
          e3.printStackTrace();
        }
      }
    }
    return str1;
  }

  @SimpleFunction
  public static String 执行命令行5(String cmd) {
    String str1 = "";
    try {
      process = Runtime.getRuntime().exec("sh");
      outputStream = new DataOutputStream(process.getOutputStream());
      inputStream = new DataInputStream(process.getInputStream());
      isreader = new InputStreamReader(inputStream);
      reader = new BufferedReader(isreader);
      byte[] data1 = (cmd + "\n").getBytes();
      outputStream.write(data1);
      outputStream.flush();
      byte[] data2 = "exit\n".getBytes();
      outputStream.write(data2);
      outputStream.flush();
      String str2 = null;
      while ((str2 = reader.readLine()) != null) {
        if (!str1.equals("")) {
          str1 = str1 + "\n" + str2; continue;
        }
        str1 = str2;
      }

      process.waitFor();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (outputStream != null) {
        try {
          outputStream.close();
        } catch (IOException e2) {
          e2.printStackTrace();
        }
      }
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e3) {
          e3.printStackTrace();
        }
      }
    }
    return str1;
  }


  @SimpleFunction
  public static int 执行命令行(String cmd) {
    int i = -1;
    try {
      process = Runtime.getRuntime().exec("su");
      outputStream = new DataOutputStream(process.getOutputStream());
      outputStream.writeBytes(cmd + "\n");
      outputStream.flush();
      outputStream.writeBytes("exit\n");
      outputStream.flush();
      process.waitFor();
      i = process.exitValue();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (outputStream != null) {
        try {
          outputStream.close();
        } catch (IOException e2) {
          e2.printStackTrace();
        }
      }
    }
    return i;
  }

  @SimpleFunction
  public static void 执行命令行3(String cmd) {
    try {
      if (process == null || outputStream == null) {
        process = Runtime.getRuntime().exec("su");
        outputStream = new DataOutputStream(process.getOutputStream());
      }
      outputStream.write((cmd + "\n").getBytes());
      outputStream.flush();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  @SimpleFunction
  public static void 模拟按键(int 键代码) {
    if (手机是否已Root() == true) {
      执行命令行3("input keyevent " + 键代码);
    }
  }

  @SimpleFunction
  public static void 模拟输入(String 内容) {
    if (手机是否已Root() == true) {
      执行命令行3("input text '" + 内容 + "'");
    }
  }

  @SimpleFunction
  public static void 模拟点击(int x, int y) {
    if (手机是否已Root() == true)
    {
      执行命令行3("input tap " + x + " " + y);
    }
  }

  @SimpleFunction
  public static void 模拟移动(int x1, int y1, int x2, int y2) {
    if (手机是否已Root() == true) {
      执行命令行3("input swipe " + x1 + " " + y1 + " " + x2 + " " + y2);
    }
  }

  @SimpleFunction
  public static String[] 取所有存储卡路径() {
    paths = new ArrayList();
    try {
      Process process = Runtime.getRuntime().exec("mount");
      InputStream is = process.getInputStream();
      InputStreamReader isr = new InputStreamReader(is);
      BufferedReader br = new BufferedReader(isr);
      String line = null;
      int mountPathIndex = 1;
      while ((line = br.readLine()) != null) {
        if ((line.contains("fat") || line.contains("fuse") || line.contains("storage")) && !line.contains("secure") && !line.contains("asec") && !line.contains("firmware") && !line.contains("shell") && !line.contains("obb") && !line.contains("legacy") && !line.contains("data")) {

          String[] parts = line.split(" ");
          int length = parts.length;
          if (mountPathIndex < length) {

            String mountPath = parts[mountPathIndex];
            if (mountPath.contains("/") && !mountPath.contains("data") && !mountPath.contains("Data"))

            { File mountRoot = new File(mountPath);
              if (mountRoot.exists() && mountRoot.isDirectory() && mountRoot.canWrite())
              {
                paths.add(mountPath); }  }
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    String[] result = new String[paths.size()];
    paths.toArray(result);
    return result;
  }

  @SimpleFunction
  public static void 截取屏幕(String path) {
    if (手机是否已Root() == true) {
      执行命令行3("screencap " + path);
    }
  }

  @SimpleFunction
  public static boolean 强制结束进程(String packagename) {
    int 执行结果 = -1;
    if (手机是否已Root() == true) {
      执行结果 = 执行命令行("am force-stop " + packagename);
    }
    return (执行结果 != -1);
  }


  @SimpleFunction
  public static int 执行命令行4(String 命令行) {

    try { Process process = Runtime.getRuntime().exec(命令行);
      process.waitFor();
      return process.exitValue(); } catch (Throwable t)

    { return -1; }

  }

  @SimpleFunction
  public static void 启动应用页面(String 包名, String 包名和activity名) { 执行命令行("am start -n " + 包名 + "/" + 包名和activity名); }
}


易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

17

主题

1782

积分

0

精华

用户组 

易积分
1674
热心
1
好评
3

活跃会员热心会员

发表于 2024-12-5 21:08:46 | 显示全部楼层
路过看看谢谢分享
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

1

主题

327

积分

0

精华

用户组 

易积分
2639
热心
0
好评
0
发表于 2024-11-21 15:36:16 | 显示全部楼层
package com.e4a.runtime;
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

0

主题

12

积分

0

精华
易积分
36
热心
0
好评
0
发表于 2024-10-19 11:19:56 | 显示全部楼层
11111111
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

0

主题

4

积分

0

精华
易积分
3
热心
0
好评
0
发表于 2024-7-19 13:15:00 | 显示全部楼层
good!!!
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

8

主题

438

积分

0

精华

用户组 

易积分
54
热心
0
好评
0
发表于 2024-7-19 11:09:14 | 显示全部楼层
1111111111
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

2

主题

210

积分

0

精华

用户组 

易积分
169
热心
0
好评
1
发表于 2024-7-19 10:24:54 来自手机 | 显示全部楼层
感谢分享
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

2

主题

108

积分

0

精华

用户组 

易积分
246
热心
0
好评
0
QQ
发表于 2024-7-18 22:41:20 来自手机 | 显示全部楼层
6666666666
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

32

主题

523

积分

0

精华

用户组 

易积分
197
热心
1
好评
5
QQ
发表于 2024-7-16 22:37:00 | 显示全部楼层
RE: E4A 的核心类库JAR包 [修改]
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

0

主题

4

积分

0

精华
易积分
8
热心
0
好评
0
发表于 2024-1-14 16:19:32 | 显示全部楼层
看看是啥?
易如意中文编程学习交流论坛有你更精彩~
回复

使用道具 举报

QQ|sitemap|免责声明|RGB颜色对照表|手机版|小黑屋| 易如意 - E4A中文编程学习交流论坛

GMT+8, 2025-5-10 13:18 , Processed in 0.092654 second(s), 34 queries .

Powered by Discuz! X3.4

© 2001-2018 eruyi.cn

返回顶部