Reputation: 121
I want to capture the screenshots from the andriod mobile to PC through some code for samsung galaxy connected via USB. I dont want to use DDMS provided by the Andriod SDK. I have to write some code in java to capture the same. Help me if somebody knows about this.
Upvotes: 0
Views: 1215
Reputation: 52810
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) {
}
}
Upvotes: 0
Reputation: 69388
Using monkeyrunner and a script like this would do the job.
#! /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')
Upvotes: 0
Reputation: 1007494
You can take a look at the code for Droid@Screen to see how to pull screenshots off the device using USB. Note that this support is undocumented and still requires the Android SDK to be installed on the host machine.
Upvotes: 1