// 截屏方法 private void getSnapshot() { wView.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); wView.layout(0, 0, wView.getMeasuredWidth(), wView.getMeasuredHeight()); //开启绘图缓存 wView.setDrawingCacheEnabled(true); wView.buildDrawingCache(); //获取绘图缓存 bitmap = wView.getDrawingCache(); android.util.Log.d(TAG, "bitmap--" + bitmap); Intent intent = new Intent(Intent.ACTION_VIEW); screenShotFielPath = Environment.getExternalStorageDirectory() + "//" + System.currentTimeMillis() + ".jpg"; File file = new File(screenShotFielPath); try { if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } FileOutputStream out = new FileOutputStream(new File(screenShotFielPath)); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) { out.flush(); out.close(); } Toast.makeText(MapActivity.this, "截屏成功", Toast.LENGTH_LONG).show(); } catch (Exception e) { android.util.Log.e(TAG, e.getMessage()); } finally { 清理绘图缓存,释放资源 wView.destroyDrawingCache(); intent.setDataAndType(Uri.fromFile(new File(screenShotFielPath)), "image/*"); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); // startActivityForResult(intent, FILE_CAMERA_RESULT_CODE); onActivityResultAboveL(intent); } }
App防止恶意截屏功能的方法:iOS、Android和鸿蒙系统的实现方案
2024-02-07 02:48:01 64 阅读