网站建设分金手指排名十三,wap网站开发协议,网站后台管理系统html,哔哩哔哩网页版登录入口文章目录 前言一、效果图二、实现步骤1.引入依赖库2.二维码生成3.布局转图片保存或者分享 总结 前言
其实现在很多分享都是我们自定义的#xff0c;更多的是在界面加了很多东西#xff0c;然后把整个界面转成图片保存相册和分享#xff0c;而且现在分享都不需要第三方… 文章目录 前言一、效果图二、实现步骤1.引入依赖库2.二维码生成3.布局转图片保存或者分享 总结 前言
其实现在很多分享都是我们自定义的更多的是在界面加了很多东西然后把整个界面转成图片保存相册和分享而且现在分享都不需要第三方直接调用系统分享大大提高工作效率本篇文章还涉及到二维码生成以及布局转图片保存相册并刷新相册功能
一、效果图 二、实现步骤
1.引入依赖库 二维码生成依赖库 implementation com.journeyapps:zxing-android-embedded:3.5.02.二维码生成
//实例化
private var codeBitmap: Bitmap? null //生成二维码
//share_url 要生成的链接或者文案第二三个参数为二维码宽高codeBitmap QRCodeUtils.createQRCodeBitmap(share_url, 120, 120, UTF-8,H, 1, Color.BLACK, Color.WHITE)
//显示到控件上
imag_ewm.setImageBitmap(codeBitmap)3.布局转图片保存或者分享 1.调用 //relative_tp为要保存的布局第二个参数为1时分享2为保存相册
startSaveBitmap(getViewBitmap(relative_tp), 2)2.实现方法 /*** 布局转图片** param v* return*/private fun getViewBitmap(v: View): Bitmap? {v.clearFocus()v.isPressed falseval willNotCache v.willNotCacheDrawing()v.setWillNotCacheDrawing(false)val color v.drawingCacheBackgroundColorv.drawingCacheBackgroundColor 0if (color ! 0) {v.destroyDrawingCache()}v.buildDrawingCache()val cacheBitmap v.drawingCache ?: return nullval bitmap Bitmap.createBitmap(cacheBitmap)v.destroyDrawingCache()v.setWillNotCacheDrawing(willNotCache)v.drawingCacheBackgroundColor colorreturn bitmap}/*** 图片保存相册** param bitmap*/private fun startSaveBitmap(bitmap: Bitmap?, type: String) {//1分享2为下载if (bitmap null) {return}// 新建目录appDir并把图片存到其下val appDir: File File((thisMyInvite.getExternalFilesDir(null)!!.getPath() System.currentTimeMillis()).toString() BarcodeBitmap)if (!appDir.exists()) {appDir.mkdir()}val fileName System.currentTimeMillis().toString() .jpgval file File(appDir, fileName)try {val fos FileOutputStream(file)bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos)fos.flush()fos.close()} catch (e: IOException) {e.printStackTrace()}if (type 1) {val intent Intent(Intent.ACTION_SEND)intent.type image/* //设置MIME类型intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(this,applicationId(也就是包名).fileprovider,file)) //需要分享的文件URIstartActivity(Intent.createChooser(intent, 分享))} else {//把file里面的图片插入到系统相册中try {MediaStore.Images.Media.insertImage(thisMyInvite.getContentResolver(),file.absolutePath, fileName, null)} catch (e: FileNotFoundException) {e.printStackTrace()}// 通知相册更新thisMyInvite.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(file)))ToastUtils.showToast(resources.getString(R.string.Successfullysaved))}}总结
总之这玩意简单如喝水欢迎大家提建议但我不会采纳希望能帮助到有需要的。