[英]how to capture an image of android device screen to PC without using DDMS…?
我想通過一些通過USB連接的三星銀河代碼,將屏幕截圖從Andriod手機捕獲到PC。 我不想使用Andriod SDK提供的DDMS。 我必須在Java中編寫一些代碼以捕獲相同的代碼。 如果有人知道我的幫助。
您可以查看Droid @ Screen的代碼,以了解如何使用USB將屏幕快照從設備中提取。 請注意,此支持尚未記錄,仍然需要在主機上安裝Android SDK。
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) {
}
}
使用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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.