Shortcut Keys for Android and android
Android provides a good implementation. From the development documentation, you can see that the View has an interface getDrawingCache (), which can obtain the Bitmap image of the View when calling this interface.
It captures the image of a View at a certain time point, including the image of all the sub-views from addView to this View. For example, when capturing an Activity, the image does not contain the dialog box floating above the activity.
The following code is an example of capturing an image and uploading it to the server through the http post interface. The core code for uploading is as follows:
Screenshot. java
package com.example.scrmdemo;import java.io.BufferedReader;import java.io.ByteArrayOutputStream;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Rect;import android.graphics.drawable.BitmapDrawable;import android.graphics.drawable.Drawable;import android.view.View;public class Screenshot {public static Bitmap takeScreenshotForView(View view) {view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap tempBit = view.getDrawingCache();Rect frame = new Rect();view.getWindowVisibleDisplayFrame(frame);int width = view.getWidth();int height = view.getHeight();Bitmap bitmap = Bitmap.createBitmap(tempBit, 0, 0, width, height);view.destroyDrawingCache();return bitmap;}public static Bitmap takeScreenshotForActivity(Activity activity) {View view = activity.getWindow().getDecorView();view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap tempBit = view.getDrawingCache();Rect frame = new Rect();view.getWindowVisibleDisplayFrame(frame);int statusBarHeight = frame.top;int width = view.getWidth();int height = view.getHeight();Bitmap bitmap = Bitmap.createBitmap(tempBit, 0, statusBarHeight, width,height - statusBarHeight);view.destroyDrawingCache();return bitmap;}public static Drawable BitmapToDrawable(Bitmap bitmap) {@SuppressWarnings("deprecation")BitmapDrawable bd = new BitmapDrawable(bitmap);Drawable drawable = (Drawable) bd;return drawable;}public static boolean savePic(Bitmap bitmap, String fileName) {try {File file = new File(fileName);if (!file.getParentFile().exists()) {file.getParentFile().mkdirs();}FileOutputStream fos = null;fos = new FileOutputStream(file);bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);fos.flush();fos.close();return true;} catch (FileNotFoundException e) {e.printStackTrace();return false;} catch (IOException e) {e.printStackTrace();return false;}}public static byte[] getBytes(Bitmap bitmap) {ByteArrayOutputStream out = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);try {out.flush();out.close();} catch (IOException e) {e.printStackTrace();}return out.toByteArray();}interface ISharePicCallBack {public final static int SHARE_OK = 1;public final static int SHARE_NOTOK = 2;public void shareResult(int resultCode, String output);}public static void share(final String urlStr, final Bitmap bitmap,final ISharePicCallBack callBack) {new Thread() {public void run() {try {URL url = new URL(urlStr);HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();httpConn.setDoOutput(true);httpConn.setDoInput(true);httpConn.setUseCaches(false);httpConn.setRequestMethod("POST");byte[] requestStringBytes = getBytes(bitmap);httpConn.setRequestProperty("Content-length", ""+ requestStringBytes.length);httpConn.setRequestProperty("Content-Type","application/octet-stream");httpConn.setRequestProperty("Connection", "Keep-Alive");httpConn.setRequestProperty("Charset", "UTF-8");OutputStream outputStream = httpConn.getOutputStream();outputStream.write(requestStringBytes);outputStream.flush();outputStream.close();if (HttpURLConnection.HTTP_OK == httpConn.getResponseCode()) {StringBuffer sb = new StringBuffer();String readLine;BufferedReader responseReader;responseReader = new BufferedReader(new InputStreamReader(httpConn.getInputStream(), "UTF-8"));while ((readLine = responseReader.readLine()) != null) {sb.append(readLine).append("\n");}responseReader.close();callBack.shareResult(ISharePicCallBack.SHARE_OK,sb.toString());} else {callBack.shareResult(ISharePicCallBack.SHARE_NOTOK, ""+ httpConn.getResponseCode());}} catch (IOException e) {callBack.shareResult(ISharePicCallBack.SHARE_NOTOK, "");e.printStackTrace();}};}.start();}}
When using this file, you must add two permissions to the AndroidManifest. xml configuration file of the Android project:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.INTERNET"/>
How can I screenshot an Android phone?
Follow these steps:
1. Press and hold the key for several seconds to display the options.
2. Press volume-key and power key simultaneously, and hold down for several seconds.
3. Of course, the landlord can install third-party software, such as QQ. 360 browsers and other software.
4. The details should refer to the software description.
5. For different phone models, contact Customer Service for free. As long as you understand it with your heart, you will surely get a solution.
Android built-in Screen Method
Many Android software require ROOT, including software. I know that ROOT is required for the four software, and the other one needs to be bought with money. I know a good solution.
First, you need to install the 360 mobile assistant on your computer, and then connect your mobile phone to your computer. You will see the current status of your mobile phone on the mobile phone management page of the 360 mobile assistant, you flip your mobile phone to the desired page, and then refresh the picture that shows the current status of your mobile phone in the "360" Mobile assistant on your computer. Click it to refresh the page you want, then you can click the key next to the refresh button. If you want to put the image into your mobile phone, just upload it to your mobile phone, but if you don't have a computer or are out there, you can't do it. You have to go to the ROOT phone.