我安装了这个库http://code.google.com/p/android-screenshot-library/。
我启动了我的Android模拟器,运行run.sh文件后它显示“服务启动成功”。
我该如何获取模拟器的屏幕截图,或者我应该从哪里获取?我使用的是最新版本。谢谢。
我安装了这个库http://code.google.com/p/android-screenshot-library/。
我启动了我的Android模拟器,运行run.sh文件后它显示“服务启动成功”。
我该如何获取模拟器的屏幕截图,或者我应该从哪里获取?我使用的是最新版本。谢谢。
打开Eclipse > 打开DDMS视图 > 从列表中选择您的模拟器 > 在您选择模拟器的位置附近按下闪烁的小相机图标
希望您能找到它。
import pl.polidea.asl.*;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.Resources.NotFoundException;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.graphics.*;
public class ScreenshotDemo extends Activity {
/*
* The ImageView used to display taken screenshots.
*/
private ImageView imgScreen;
private ServiceConnection aslServiceConn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
aslProvider = IScreenshotProvider.Stub.asInterface(service);
}
};
private IScreenshotProvider aslProvider = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imgScreen = (ImageView)findViewById(R.id.imgScreen);
Button btn = (Button)findViewById(R.id.btnTakeScreenshot);
btn.setOnClickListener(btnTakeScreenshot_onClick);
// connect to ASL service
//Intent intent = new Intent(ScreenshotService.class.getName());
Intent intent = new Intent();
intent.setClass(this, ScreenshotService.class);
//intent.addCategory(Intent.ACTION_DEFAULT);
bindService (intent, aslServiceConn, Context.BIND_AUTO_CREATE);
}
@Override
public void onDestroy() {
unbindService(aslServiceConn);
super.onDestroy();
}
private View.OnClickListener btnTakeScreenshot_onClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
if (aslProvider == null)
Toast.makeText(ScreenshotDemo.this, R.string.n_a, Toast.LENGTH_SHORT).show();
else if (!aslProvider.isAvailable())
Toast.makeText(ScreenshotDemo.this, R.string.native_n_a, Toast.LENGTH_SHORT).show();
else {
String file = aslProvider.takeScreenshot();
if (file == null)
Toast.makeText(ScreenshotDemo.this, R.string.screenshot_error, Toast.LENGTH_SHORT).show();
else {
Toast.makeText(ScreenshotDemo.this, R.string.screenshot_ok, Toast.LENGTH_SHORT).show();
Bitmap screen = BitmapFactory.decodeFile(file);
imgScreen.setImageBitmap(screen);
}
}
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// squelch
}
}
};
}
DDMS具有截取视图截图的功能。
在Eclipse中,打开DDMS透视图并在设备布局中单击屏幕截图图标。