周六,可惜,我在上搬砖,事情不是很多,分享一段项目中用到的截屏分享代码。
public void screenshot() { // 获取屏幕 View dView = getWindow().getDecorView(); dView.setDrawingCacheEnabled(true); dView.buildDrawingCache(); Bitmap bmp = dView.getDrawingCache(); if (bmp != null) { try { // 获取内置SD卡路径 String sdCardPath = Environment.getExternalStorageDirectory().getPath(); // 图片文件路径 filePath = sdCardPath + File.separator + "screenshot.png"; File file = new File(filePath); FileOutputStream os = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 100, os); os.flush(); os.close(); } catch (Exception e) { } // 系统分享代码:Intent imageIntent = new Intent(Intent.ACTION_SEND); // //由文件得到uri // Uri uri = Uri.fromFile(file); // imageIntent.putExtra(Intent.EXTRA_STREAM, uri); // imageIntent.setType("image/*"); // startActivity(Intent.createChooser(imageIntent, "分享到")); bitmap = BitmapFactory.decodeFile(filePath); } }后面还是用微信sdk的分享,因为安卓系统自带的分享代码很方便但缺点也很明显,直接分享图片时发现不会返回自己的app,查看多方资料无果,并且分享文字还是提示:返回第三方工具,有点不友好,如果你对分享要求不高,可以试试这个分享。