我希望通过USB连接的三星Galaxy的代码捕获从andriod mobile到PC的屏幕截图。我不想使用Andriod SDK提供的DDMS。我必须在java中编写一些代码来捕获相同的代码。如果有人知道这个,请帮助我。
答案 0 :(得分:1)
您可以查看Droid@Screen的代码,了解如何使用USB从设备中提取屏幕截图。请注意,此支持未记录,仍需要在主机上安装Android SDK。
答案 1 :(得分:0)
使用monkeyrunner和这样的脚本可以完成这项工作。
#! /opt/android-sdk-linux_86/tools/monkeyrunner
# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()
# Takes a screenshot
result = device.takeSnapshot()
# Writes the screenshot to a file
result.writeToFile('/tmp/device.png','png')
答案 2 :(得分:0)
First call this method oncreate();
new screenshot().execute();
after create given class:
class screenshot extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... args) {
Log.e("Screenshot", "Called");
mView = view.getRootView();
mView.setDrawingCacheEnabled(true);
b = mView.getDrawingCache();
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString("myapp")
+ ".jpg");
Log.e("My_PatH", "" + myPath);
if (myPath.exists())
myPath.delete();
FileOutputStream fos = null;
try {
fos = new FileOutputStream(myPath);
b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
MediaStore.Images.Media.insertImage(getContentResolver(), b,
"Screen", "screen");
Log.e("Bitmap", "" + b);
Log.e("myPath", "" + myPath);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String args) {
}
}