当前位置:首页 » 安卓系统 » androidadbshell

androidadbshell

发布时间: 2022-05-25 08:38:44

A. 如何在android里面执行adb shell命令

ADB接口的作用主要是让电脑等其它设备控制安卓系统的,所以,称为“中间桥”;
不是为安卓自已用的,自已可直接执行称为SHELL,这与ADB无关。
所以安卓java不一定有封装的ADB类。电脑上有ADB服务程序,端口5037,
它是中间程序,与安卓系统上守护进程(Daemon)通讯。
如果要在自已的手机上应该也能执行adb命令,应该直接跟守护进程
(Daemon)通讯了。网络上可以搜到的方法并不满意。

楼主用exec执行CMD命令,这已不是ADB接口了,这是系统的SHELL了!!!

自已用socket/tcp直接发命令效果不知怎样,地址用127.0.0.1, 安卓daemon进程的端口
5555 是奇数开始。

B. 如何在android程序中执行adb shell命令

Android中执行adb shell命令的方式如下:<pre t="code" l="java"> /**
* 执行一个shell命令,并返回字符串值
*
* @param cmd
* 命令名称参数组成的数组(例如:{"/system/bin/cat", "/proc/version"})
* @param workdirectory
* 命令执行路径(例如:"system/bin/")
* @return 执行结果组成的字符串
* @throws IOException
*/
public static synchronized String run(String[] cmd, String workdirectory)
throws IOException {
StringBuffer result = new StringBuffer();
try {
// 创建操作系统进程(也可以由Runtime.exec()启动)
// Runtime runtime = Runtime.getRuntime();
// Process proc = runtime.exec(cmd);
// InputStream inputstream = proc.getInputStream();
ProcessBuilder builder = new ProcessBuilder(cmd);
InputStream in = null;
// 设置一个路径(绝对路径了就不一定需要)
if (workdirectory != null) {
// 设置工作目录(同上)
builder.directory(new File(workdirectory));
// 合并标准错误和标准输出
builder.redirectErrorStream(true);
// 启动一个新进程
Process process = builder.start();
// 读取进程标准输出流
in = process.getInputStream();
byte[] re = new byte[1024];
while (in.read(re) != -1) {
result = result.append(new String(re));
}
}
// 关闭输入流
if (in != null) {
in.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return result.toString();
} android系统底层采用的是linux,所以adb这样的linux指令是可以在java代码中调用的,可以使用ProcessBuilder 这个方法来执行对应的指令。还可以通过如下方式执行:
<pre t="code" l="java">Process p = Runtime.getRuntime().exec("ls");
String data = null;
BufferedReader ie = new BufferedReader(new InputStreamReader(p.getErrorStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String error = null;
while ((error = ie.readLine()) != null
!error.equals("null")) {
data += error + "\n";
}
String line = null;
while ((line = in.readLine()) != null
!line.equals("null")) {
data += line + "\n";
}

Log.v("ls", data);

C. 如何在android程序中执行adb shell命令

android程序执行adbshell命令(实例源码)packagenet.gimite.nativeexe;importjava.io.BufferedReader;importjava.io.FileOutputStream;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.net.HttpURLConnection;importjava.net.MalformedURLException;importjava.net.URL;importnet.gimite.nativeexe.R;importandroid.app.Activity;importandroid.os.Bundle;importandroid.os.Handler;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.*;{privateTextViewoutputView;privateButtonlocalRunButton;privateEditTextlocalPathEdit;privateHandlerhandler=newHandler();privateEditTexturlEdit;privateButtonremoteRunButton;/**.*/@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);outputView=(TextView)findViewById(R.id.outputView);localPathEdit=(EditText)findViewById(R.id.localPathEdit);localRunButton=(Button)findViewById(R.id.localRunButton);localRunButton.setOnClickListener(onLocalRunButtonClick);}=newOnClickListener(){publicvoidonClick(Viewv){Stringoutput=exec(localPathEdit.getText().toString());output(output);//try{//////Processprocess=Runtime.getRuntime().exec(localPathEdit.getText().toString());////}catch(IOExceptione){////TODOAuto-generatedcatchblock//e.printStackTrace();//}}};//ExecutesUNIXcommand.privateStringexec(Stringcommand){try{Processprocess=Runtime.getRuntime().exec(command);BufferedReaderreader=newBufferedReader(newInputStreamReader(process.getInputStream()));intread;char[]buffer=newchar[4096];StringBufferoutput=newStringBuffer();while((read=reader.read(buffer))>0){output.append(buffer,0,read);}reader.close();process.waitFor();returnoutput.toString();}catch(IOExceptione){thrownewRuntimeException(e);}catch(InterruptedExceptione){thrownewRuntimeException(e);}}privatevoiddownload(StringurlStr,StringlocalPath){try{URLurl=newURL(urlStr);HttpURLConnectionurlconn=(HttpURLConnection)url.openConnection();urlconn.setRequestMethod("GET");urlconn.setInstanceFollowRedirects(true);urlconn.connect();InputStreamin=urlconn.getInputStream();FileOutputStreamout=newFileOutputStream(localPath);intread;byte[]buffer=newbyte[4096];while((read=in.read(buffer))>0){out.write(buffer,0,read);}out.close();in.close();urlconn.disconnect();}catch(MalformedURLExceptione){thrownewRuntimeException(e);}catch(IOExceptione){thrownewRuntimeException(e);}}privatevoidoutput(finalStringstr){Runnableproc=newRunnable(){publicvoidrun(){outputView.setText(str);}};handler.post(proc);}}

D. 安卓怎么进入adb shell

如果你配置了adb的环境变量 那么你连接手机以后,直接执行 adb shell 则进入命令模式了 如果你没有配置环境变量,那么,你需要进入sdk\platform-tools目录下 再执行 adb shell

E. 如何在android程序中执行adb shell命令

android中执行shell命令有两种方式:

1.直接在代码中用java提供的Runtime 这个类来执行命令,以下为完整示例代码。

public void execCommand(String command) throws IOException {

// start the ls command running

//String[] args = new String[]{"sh", "-c", command};

Runtime runtime = Runtime.getRuntime();

Process proc = runtime.exec(command); //这句话就是shell与高级语言间的调用

//如果有参数的话可以用另外一个被重载的exec方法

//实际上这样执行时启动了一个子进程,它没有父进程的控制台

//也就看不到输出,所以需要用输出流来得到shell执行后的输出

InputStream inputstream = proc.getInputStream();

InputStreamReader inputstreamreader = new InputStreamReader(inputstream);

BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

// read the ls output

String line = "";

StringBuilder sb = new StringBuilder(line);

while ((line = bufferedreader.readLine()) != null) {

//System.out.println(line);

sb.append(line);

sb.append(' ');

}

//tv.setText(sb.toString());

//使用exec执行不会等执行成功以后才返回,它会立即返回

//所以在某些情况下是很要命的(比如复制文件的时候)

//使用wairFor()可以等待命令执行完成以后才返回

try {

if (proc.waitFor() != 0) {

System.err.println("exit value = " + proc.exitValue());

}

}

catch (InterruptedException e) {

System.err.println(e);

}

}

}


2.直接安装shell模拟器,即已经开发好的android应用,启动后类似windows的dos命令行,可以直接安装使用,可执行常用的linux命令,应用在附件。



F. android 进入adb shell

  1. 手机设置--开发者选项,进入之后勾选USB调试功能,没有开发者选项的进入关于手机---软件版本,不停的点击版本号即可调处开发者选项。

  2. 载入ADB工具,快捷键WIN+R打开,输入cmd,打开命令控制台,输入cd+空格+adb工具包的路径,比如cd c:/urser/administrator/desktop/adb 这个路径是放在桌面上的路径,如果用一些刷机软件直接进入adb控制台的就不需要加载了。

  3. 连接手机,首先输入dab devices,如果弹出XXXXXdeviecs,X表示机型以及一些杂七杂八的英文,表示连接,直接输入adb shell即可进入linux环境直行shell命令。

  4. http://wenku..com/link?url=vbDamH6atI1cxrY64c7Yi_lZ7pHCQPavGUQMKw_-S6web0H7wOcFJkYzN-sK这个是主要使用的一些shell命令。

G. android apk 怎么执行adb shell命令

android中执行shell命令有两种方式: 1.直接在代码中用java提供的Runtime 这个类来执行命令,以下为完整示例代码。 public void execCommand(String command) throws IOException { // start the ls command running //String[] args = new String[]{"sh", "-c", command}; Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec(command); //这句话就是shell与高级语言间的调用 //如果有参数的话可以用另外一个被重载的exec方法 //实际上这样执行时启动了一个子进程,它没有父进程的控制台 //也就看不到输出,所以需要用输出流来得到shell执行后的输出 InputStream inputstream = proc.getInputStream(); InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); // read the ls output String line = ""; StringBuilder sb = new StringBuilder(line); while ((line = bufferedreader.readLine()) != null) { //System.out.println(line); sb.append(line); sb.append('\n'); } //tv.setText(sb.toString()); //使用exec执行不会等执行成功以后才返回,它会立即返回 //所以在某些情况下是很要命的(比如复制文件的时候) //使用wairFor()可以等待命令执行完成以后才返回 try { if (proc.waitFor() != 0) { System.err.println("exit value = " + proc.exitValue()); } } catch (InterruptedException e) { System.err.println(e); } } } 2.直接安装shell模拟器,即已经开发好的android应用,启动后类似windows的dos命令行,可以直接安装使用,可执行常用的linux命令,应用在附件。 shell.apk大小:455.51K所需财富值:5 已经过网络安全检测,放心下载 点击下载下载量:1

H. 如何进入Android adb shell 命令行模式

如果你配置了adb的环境变量
那么你连接手机以后,直接执行
adb
shell
则进入命令模式了
如果你没有配置环境变量,那么,你需要进入sdk\platform-tools目录下
再执行
adb
shell

I. android如何通过adb shell 模拟home键盘切换应用

1:查看当前模拟器或者Android设备实例的状态
一般在使用前都会使用adb devices这个命令查看一下模拟器的状态,通过这个命令得到ADB的回应信息,可以看到ADB作为回应为每个实例制定了相关的信息
1.1:emulator-5554为实例名称
1.2:device为实例连接状态,device表示此实例正与adb相连接,offline表示此实例没有与adb连接或者无法响应

2:安装和卸载APK应用程序
你可以从电脑上复制一个APK应用到模拟器或者Android设备上,通过adb install <path_to_apk>安装软件,adb uninstall <packageName>卸载软件,如果你不知道这个包名,在AndroidManifest.xml里的找package=""就可以了
2.1: 先把apk文件拷贝到sdk目录下的tools

2.2: 进入dos下切换到SDK的安装路径下的tools目录
2.3 :执行安装命令
adb install <path_to_apk>

发生的错误,因为我连接了真机,而且也打开了模拟器,所以adb给我的回应信息是“比一个多的驱动设备和模拟器”,我最后关闭掉了模拟器在运行安装命令,就提示安装成功了

卸载APK

3:从本机上复制文件到模拟器或者Android设备
adb push <本地路径><远程路径>,<本地路径>指的是自己的机器上或者模拟器上的目标文件,<远程路径>指的是远程设备实例上的目标文件
4:从模拟器复制文件到模拟器或者Android设备
adb pull <远程路径><本地路径>,<本地路径>指的是自己的机器上或者模拟器上的目标文件,<远程路径>指的是远程设备实例上的目标文件
5:使用shell命令
输入adb shell就可以进入shell命令行了,可以使用一些常用的shell命令,如:ls命令列出了文件

J. 如何在android程序中执行adb shell命令

在android程序中执行adb shell命令:

package net.gimite.nativeexe;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import net.gimite.nativeexe.R;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class MainActivity extends Activity {

private TextView outputView;
private Button localRunButton;
private EditText localPathEdit;
private Handler handler = new Handler();
private EditText urlEdit;
private Button remoteRunButton;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

outputView = (TextView)findViewById(R.id.outputView);
localPathEdit = (EditText)findViewById(R.id.localPathEdit);
localRunButton = (Button)findViewById(R.id.localRunButton);
localRunButton.setOnClickListener(onLocalRunButtonClick);


}

private OnClickListener onLocalRunButtonClick = new OnClickListener() {
public void onClick(View v) {
String output = exec(localPathEdit.getText().toString());
output(output);
// try {
//
// // Process process = Runtime.getRuntime().exec(localPathEdit.getText().toString());
//
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
};


// Executes UNIX command.
private String exec(String command) {
try {
Process process = Runtime.getRuntime().exec(command);
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
process.waitFor();
return output.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

private void download(String urlStr, String localPath) {
try {
URL url = new URL(urlStr);
HttpURLConnection urlconn = (HttpURLConnection)url.openConnection();
urlconn.setRequestMethod("GET");
urlconn.setInstanceFollowRedirects(true);
urlconn.connect();
InputStream in = urlconn.getInputStream();
FileOutputStream out = new FileOutputStream(localPath);
int read;
byte[] buffer = new byte[4096];
while ((read = in.read(buffer)) > 0) {
out.write(buffer, 0, read);
}
out.close();
in.close();
urlconn.disconnect();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private void output(final String str) {
Runnable proc = new Runnable() {
public void run() {
outputView.setText(str);
}
};
handler.post(proc);
}

}

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

效果图:

热点内容
自己怎么搭建网站服务器 发布:2025-08-22 00:36:54 浏览:141
按键精灵只能做手游脚本吗 发布:2025-08-22 00:31:22 浏览:152
php网站制作 发布:2025-08-22 00:31:19 浏览:488
java的http编程 发布:2025-08-21 23:56:32 浏览:988
大学数据库试题 发布:2025-08-21 23:56:28 浏览:801
沾福卡的算法 发布:2025-08-21 23:38:26 浏览:337
java极光 发布:2025-08-21 23:38:14 浏览:709
php路由框架 发布:2025-08-21 23:32:17 浏览:771
超微ipmi无法解析服务器dns地址 发布:2025-08-21 23:31:14 浏览:162
私服魔域脚本 发布:2025-08-21 23:29:34 浏览:55