How to take screenshot of Android(Emulator) using

2019-05-07 08:06发布

I had installed this library http://code.google.com/p/android-screenshot-library/.

I had started my Android emulator ,when i run the run.sh file it is saying "Service Started Sucessfully".

How Should i or where can i get the Screen shots of my emulator.I am using all latest versions.Thank You.

3条回答
放荡不羁爱自由
2楼-- · 2019-05-07 08:18
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
        }

    }
};
}
查看更多
Juvenile、少年°
3楼-- · 2019-05-07 08:39

DDMS has a feature to taking screenshots of views.

In Eclipse, open DDMS perspective and click on screen capture icon in Devices layout.

查看更多
姐就是有狂的资本
4楼-- · 2019-05-07 08:44

Open Eclipse > open DDMS View > Select your Emulator out of the list > press the little blinking Camera Icon near where you select your Emulator from the list

Hope you find it.

查看更多
登录 后发表回答