安卓截屏;前台服务
private var mediaProjectionManager: MediaProjectionManager? = nullval REQUEST_MEDIA_PROJECTION = 10001private var isstartservice = true//启动MediaService服务fun startMediaService() {if (isstartservice) {startService(Intent(this, MediaService::class.java))isstartservice = false}}//停止MediaService服务fun stopMediaService(context: Context) {val intent = Intent(context, MediaService::class.java)context.stopService(intent)}// 申请截屏权限private fun getScreenShotPower() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {mediaProjectionManager =getSystemService(Context.MEDIA_PROJECTION_SERVICE) as MediaProjectionManagerif (mediaProjectionManager != null) {val intent = mediaProjectionManager!!.createScreenCaptureIntent()startActivityForResult(intent, REQUEST_MEDIA_PROJECTION)}}}@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)override fun onActivityResult(requestCode: Int, resultCode: Int, @Nullable data: Intent?) {super.onActivityResult(requestCode, resultCode, data)if (requestCode == REQUEST_MEDIA_PROJECTION && data != null) {
// mediaProjection = mediaProjectionManager!!.getMediaProjection(RESULT_OK, data)val mediaPro = mediaProjectionManager!!.getMediaProjection(RESULT_OK, data)val bitmap = screenShot(mediaPro) //截屏val bs = getBitmapByte(bitmap)//对图片进行处理逻辑 例如可以保存本地、进行图片分享等等操作Log.e("WWW", "EEE" + bitmap)if (bitmap != null) {if (typeShare != -1) {if (typeShare == 0) {/*** 微信分享*/shareWechat(bitmap)} else if (typeShare == 1) {/*** 保存到本地相册*/bitmap?.let { it1 -> ImageSaver.saveBitmapToGallery(this, it1, "-", "+++") }stopMediaService(this)}}}// startRecord() //三:录屏
// if (!isStart) {
// isStart = !isStart
// startPlayRoute()
// multiple = 150f
// } else {
// multiple = 150f
// }
// isShowShareTipsPop = true}}/*** 分享到微信* @param view View*/private fun shareWechat(view: Bitmap?) {
// var bmp: Bitmap? = loadBitmapFromViewBySystem(view)val imgObj = WXImageObject(view)val msg = WXMediaMessage()msg.mediaObject = imgObjval thumbBmp = Bitmap.createScaledBitmap(view!!,150,150,true)msg.thumbData = bmpToByteArray(thumbBmp, true)val req = SendMessageToWX.Req()req.transaction = buildTransaction("img")req.message = msgreq.scene = SendMessageToWX.Req.WXSceneSession // 分享到对话框api!!.sendReq(req)stopMediaService(this)}@RequiresApi(api = Build.VERSION_CODES.KITKAT)fun screenShot(mediaProjection: MediaProjection): Bitmap? {val wm1 = this.windowManagerval width = wm1.defaultDisplay.widthval height = wm1.defaultDisplay.heightObjects.requireNonNull(mediaProjection)@SuppressLint("WrongConstant") val imageReader: ImageReader =ImageReader.newInstance(width, height, PixelFormat.RGBA_8888, 60)var virtualDisplay: VirtualDisplay? = nullif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {virtualDisplay = mediaProjection.createVirtualDisplay("screen",width,height,1,DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,imageReader.getSurface(),null,null)}SystemClock.sleep(1000)//取最新的图片val image: Image = imageReader.acquireLatestImage()// Image image = imageReader.acquireNextImage();//释放 virtualDisplay,不释放会报错virtualDisplay!!.release()return image2Bitmap(image)}// 位图转 Byteprivate fun getBitmapByte(bitmap: Bitmap?): ByteArray {val out = ByteArrayOutputStream()// 参数1转换类型,参数2压缩质量,参数3字节流资源bitmap!!.compress(Bitmap.CompressFormat.PNG, 100, out)try {out.flush()out.close()} catch (e: IOException) {e.printStackTrace()}return out.toByteArray()}@RequiresApi(api = Build.VERSION_CODES.KITKAT)fun image2Bitmap(image: Image?): Bitmap? {if (image == null) {println("image 为空")return null}val width: Int = image.getWidth()val height: Int = image.getHeight()val planes: Array<Image.Plane> = image.planesval buffer: ByteBuffer = planes[0].bufferval pixelStride: Int = planes[0].pixelStrideval rowStride: Int = planes[0].rowStrideval rowPadding = rowStride - pixelStride * widthval bitmap =Bitmap.createBitmap(width + rowPadding / pixelStride, height, Bitmap.Config.ARGB_8888)bitmap.copyPixelsFromBuffer(buffer)//截取图片// Bitmap cutBitmap = Bitmap.createBitmap(bitmap,0,0,width/2,height/2);//压缩图片// Matrix matrix = new Matrix();// matrix.setScale(0.5F, 0.5F);// System.out.println(bitmap.isMutable());// bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, false);image.close()return bitmap}
package com.allynav.iefa.service
import android.R
import android.app.*
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.os.Build
import android.os.IBinder
import androidx.core.app.NotificationCompat
/**
*@author zd
*@time 2023/4/10 8:55
*@description : 截屏前台服务
*
**/
class MediaService : Service() {private val NOTIFICATION_CHANNEL_ID = "com.tencent.trtc.apiexample.MediaService"private val NOTIFICATION_CHANNEL_NAME = "com.tencent.trtc.apiexample.channel_name"private val NOTIFICATION_CHANNEL_DESC = "com.tencent.trtc.apiexample.channel_desc"override fun onCreate() {super.onCreate()startNotification()}fun startNotification() {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//Call Start foreground with notificationval notificationIntent = Intent(this, MediaService::class.java)val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0)val notificationBuilder: NotificationCompat.Builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID).setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.alert_dark_frame)).setSmallIcon(R.drawable.alert_dark_frame).setContentTitle("Starting Service").setContentText("Starting monitoring service").setContentIntent(pendingIntent)val notification: Notification = notificationBuilder.build()val channel = NotificationChannel(NOTIFICATION_CHANNEL_ID,NOTIFICATION_CHANNEL_NAME,NotificationManager.IMPORTANCE_DEFAULT)channel.description = NOTIFICATION_CHANNEL_DESCval notificationManager =getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManagernotificationManager.createNotificationChannel(channel)startForeground(1,notification) //必须使用此方法显示通知,不能使用notificationManager.notify,否则还是会报上面的错误}}override fun onBind(intent: Intent?): IBinder {throw UnsupportedOperationException("Not yet implemented")}
}
相关文章:
安卓截屏;前台服务
private var mediaProjectionManager: MediaProjectionManager? nullval REQUEST_MEDIA_PROJECTION 10001private var isstartservice true//启动MediaService服务fun startMediaService() {if (isstartservice) {startService(Intent(this, MediaService::class.java))iss…...

C++ PrimerPlus 复习 第八章 函数探幽
第一章 命令编译链接文件 make文件 第二章 进入c 第三章 处理数据 第四章 复合类型 (上) 第四章 复合类型 (下) 第五章 循环和关系表达式 第六章 分支语句和逻辑运算符 第七章 函数——C的编程模块(上ÿ…...

JavaScript-Ajax-axios-Xhr
JS的异步请求 主要有xhr xmlHttpRequest 以及axios 下面给出代码以及详细用法,都写在了注释里 直接拿去用即可 测试中默认的密码为123456 账号admin 其他一律返回登录失败 代码实例 <!DOCTYPE html> <html lang"en"> <head><…...
怎样查看kafka写数据送到topic是否成功
要查看 Kafka 写数据是否成功送到主题(topic),可以通过以下几种方法来进行确认: Kafka 生产者确认机制:Kafka 提供了生产者的确认机制,您可以在创建生产者时设置 acks 属性来控制确认级别。常见的确认级别包…...

腾讯mini项目-【指标监控服务重构】2023-08-16
今日已办 v1 验证 StageHandler 在处理消息时是否为单例,【错误尝试】 type StageHandler struct { }func (s StageHandler) Middleware1(h message.HandlerFunc) message.HandlerFunc {return func(msg *message.Message) ([]*message.Message, error) {log.Log…...

PTA:7-3 两个递增链表的差集
^两个递增链表的差集 题目输入样例输出样例 代码 题目 输入样例 5 1 3 5 7 9 3 2 3 5输出样例 3 1 7 9代码 #include <iostream> #include <list> #include <unordered_set> using namespace std; int main() {int n1, n2;cin >> n1;list<int&g…...

智能合约漏洞案例,DEI 漏洞复现
智能合约漏洞案例,DEI 漏洞复现 1. 漏洞简介 https://twitter.com/eugenioclrc/status/1654576296507088906 2. 相关地址或交易 https://explorer.phalcon.xyz/tx/arbitrum/0xb1141785b7b94eb37c39c37f0272744c6e79ca1517529fec3f4af59d4c3c37ef 攻击交易 3. …...
Attention is all you need 论文笔记
该论文引入Transformer,主要核心是自注意力机制,自注意力(Self-Attention)机制是一种可以考虑输入序列中所有位置信息的机制。 RNN介绍 引入RNN为了更好的处理序列信息,比如我 吃 苹果,前后的输入之间是有…...

Hdoop伪分布式集群搭建
文章目录 Hadoop安装部署前言1.环境2.步骤3.效果图 具体步骤(一)前期准备(1)ping外网(2)配置主机名(3)配置时钟同步(4)关闭防火墙 (二)…...
java临时文件
临时文件 有时候,我们程序运行时需要产生中间文件,但是这些文件只是临时用途,并不做长久保存。 我们可以使用临时文件,不需要长久保存。 public static File createTempFile(String prefix, String suffix)prefix 前缀 suffix …...
C++中的<string>头文件 和 <cstring>头文件简介
C中的<string>头文件 和 <cstring>头文件简介 在C中<string> 和 <cstring> 是两个不同的头文件。 <string> 是C标准库中的头文件,定义了一个名为std::string的类,提供了对字符串的操作如size()、length()、empty() 及字…...
安装MySQL
Centos7下安装MySQL详细步骤_centos7安装mysql教程_欢欢李的博客-CSDN博客...

输入学生成绩,函数返回最大元素的数组下标,求最高分学生成绩(输入负数表示输入结束)
scanfscore()函数用于输入学生的成绩 int scanfscore(int score[N])//输入学生的成绩 {int i -1;do {i;printf("输入学生成绩:");scanf("%d", &score[i]);} while (score[i] > 0);return i; } findmax()用于寻找最大值 int findmax(int score[N…...
常用音频接口:TDM,PDM,I2S,PCM
常用音频接口:TDM,PDM,I2S,PCM_tdm音频_沙漠的甲壳虫的博客-CSDN博客 I2S/PCM接口及音频codec_音频pcm接口模块设计-CSDN博客 2个TDM8功放调试ing_周龙(AI湖湘学派)的博客-CSDN博客 数字音频接口时序----IIS、TDM、PCM、PDM_td…...

git clone报错Failed to connect to github.com port 443 after 21055 ms:
git 设置代理端口号 git config --global http.proxy http://127.0.0.1:10085 和 git config --global https.proxy http://127.0.0.1:10085 然后就可以成功git clone hugging face的数据集了 如果是https://huggingface.co/datasets/shibing624/medical/tree/main 那么…...

【操作系统】深入浅出死锁问题
死锁的概念 在多线程编程中,我们为了防止多线程竞争共享资源而导致数据错乱,都会在操作共享资源而导致数据错乱,都会在操作共享资源之前加上互斥锁,只有成功获得到锁的线程,才能操作共享资源,获取不到锁的…...
springboot实现webSocket服务端和客户端demo
1:pom导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-websocket</artifactId><version>2.2.7.RELEASE</version></dependency>2:myWebSocketClien…...
代码走读: FFMPEG-ffplayer02
AVFrame int attribute_align_arg avcodec_receive_frame(AVCodecContext *avctx, AVFrame *frame) 选取一个音频解码器 和 一个视频解码器分别介绍该解码器功能 音频G722 g722dec.c -> g722_decode_frame 通过 ff_get_buffer 给 传入的 frame 指针分配内存 g722_decode_…...

【数据结构】——排序算法的相关习题
目录 一、选择题题型一 (插入排序)1、直接插入排序2、折半插入排序3、希尔排序 题型二(交换排序)1、冒泡排序2、快速排序 题型三(选择排序)1、简单选择排序~2、堆排序 ~题型四(归并排序…...

C高级day5(Makefile)
一、Xmind整理: 二、上课笔记整理: 1.#----->把带参宏的参数替换成字符串 #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX(a,b) a>b?a:b #define STR(n) #n int main(int argc, const char *argv…...
SkyWalking 10.2.0 SWCK 配置过程
SkyWalking 10.2.0 & SWCK 配置过程 skywalking oap-server & ui 使用Docker安装在K8S集群以外,K8S集群中的微服务使用initContainer按命名空间将skywalking-java-agent注入到业务容器中。 SWCK有整套的解决方案,全安装在K8S群集中。 具体可参…...

前端导出带有合并单元格的列表
// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

Java面试专项一-准备篇
一、企业简历筛选规则 一般企业的简历筛选流程:首先由HR先筛选一部分简历后,在将简历给到对应的项目负责人后再进行下一步的操作。 HR如何筛选简历 例如:Boss直聘(招聘方平台) 直接按照条件进行筛选 例如:…...

图表类系列各种样式PPT模版分享
图标图表系列PPT模版,柱状图PPT模版,线状图PPT模版,折线图PPT模版,饼状图PPT模版,雷达图PPT模版,树状图PPT模版 图表类系列各种样式PPT模版分享:图表系列PPT模板https://pan.quark.cn/s/20d40aa…...
重启Eureka集群中的节点,对已经注册的服务有什么影响
先看答案,如果正确地操作,重启Eureka集群中的节点,对已经注册的服务影响非常小,甚至可以做到无感知。 但如果操作不当,可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...

HashMap中的put方法执行流程(流程图)
1 put操作整体流程 HashMap 的 put 操作是其最核心的功能之一。在 JDK 1.8 及以后版本中,其主要逻辑封装在 putVal 这个内部方法中。整个过程大致如下: 初始判断与哈希计算: 首先,putVal 方法会检查当前的 table(也就…...

安宝特案例丨Vuzix AR智能眼镜集成专业软件,助力卢森堡医院药房转型,赢得辉瑞创新奖
在Vuzix M400 AR智能眼镜的助力下,卢森堡罗伯特舒曼医院(the Robert Schuman Hospitals, HRS)凭借在无菌制剂生产流程中引入增强现实技术(AR)创新项目,荣获了2024年6月7日由卢森堡医院药剂师协会࿰…...

在Mathematica中实现Newton-Raphson迭代的收敛时间算法(一般三次多项式)
考察一般的三次多项式,以r为参数: p[z_, r_] : z^3 (r - 1) z - r; roots[r_] : z /. Solve[p[z, r] 0, z]; 此多项式的根为: 尽管看起来这个多项式是特殊的,其实一般的三次多项式都是可以通过线性变换化为这个形式…...

Git 3天2K星标:Datawhale 的 Happy-LLM 项目介绍(附教程)
引言 在人工智能飞速发展的今天,大语言模型(Large Language Models, LLMs)已成为技术领域的焦点。从智能写作到代码生成,LLM 的应用场景不断扩展,深刻改变了我们的工作和生活方式。然而,理解这些模型的内部…...
怎么让Comfyui导出的图像不包含工作流信息,
为了数据安全,让Comfyui导出的图像不包含工作流信息,导出的图像就不会拖到comfyui中加载出来工作流。 ComfyUI的目录下node.py 直接移除 pnginfo(推荐) 在 save_images 方法中,删除或注释掉所有与 metadata …...