在Android中分享屏幕截图的技术性解决方法如下:
代码示例:
View view = getWindow().getDecorView().getRootView();
view.setDrawingCacheEnabled(true);
Bitmap screenshot = Bitmap.createBitmap(view.getDrawingCache());
view.setDrawingCacheEnabled(false);
代码示例:
String filename = "screenshot.png";
String dirPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Screenshots";
File dir = new File(dirPath);
if (!dir.exists()) {
dir.mkdirs();
}
File file = new File(dirPath, filename);
try {
FileOutputStream fos = new FileOutputStream(file);
screenshot.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
代码示例:
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("image/png");
Uri uri = Uri.fromFile(file);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(shareIntent, "分享截图"));
以上是在Android中分享屏幕截图的完整代码示例。