take screenshot and share it - Android User Interface

Android examples for User Interface:ScreenShot

Description

take screenshot and share it

Demo Code


//package com.java2s;

import android.app.Activity;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;

import android.view.View;

public class Main {
    /**/* w  w  w  .java  2 s .  c  o  m*/
     * Also see
     * http://stackoverflow.com/questions/10296711/androidtake-screenshot-and-share-it
     * @param activity
     * @return
     */
    public static Bitmap takeScreenShot(Activity activity) {
        View rootView = activity.getWindow().getDecorView();
        Bitmap bmp = Bitmap.createBitmap(rootView.getWidth(),
                rootView.getHeight(), Bitmap.Config.RGB_565);
        rootView.draw(new Canvas(bmp));
        //Remove title bar
        Rect frame = new Rect();
        activity.getWindow().getDecorView()
                .getWindowVisibleDisplayFrame(frame);
        int statusBarHeight = frame.top;
        bmp = Bitmap
                .createBitmap(bmp, 0, statusBarHeight, rootView.getWidth(),
                        rootView.getHeight() - statusBarHeight);
        return bmp;
    }
}

Related Tutorials