登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
Gitee AI
NEW
我知道了
查看详情
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
手机/移动开发
>
Android组件/项目
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
5
Star
43
Fork
19
黎明白昼
/
HQW
代码
Issues
16
Pull Requests
0
Wiki
统计
流水线
服务
Gitee Pages
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
我知道了,不再自动展开
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
发送通知
待办的
#I9H6JP
黎明白昼
拥有者
创建于
2024-04-16 17:14
``` package com.tencent.qcloud.tuikit.tuichat.notification; import android.Manifest; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.widget.RemoteViews; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import com.huanqi.android.Utils.HQWLogUtil; import com.tencent.imsdk.v2.V2TIMConversation; import com.tencent.qcloud.tuicore.TUIConstants; import com.tencent.qcloud.tuicore.TUICore; import com.tencent.qcloud.tuikit.timcommon.TIMCommonService; import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean; import com.tencent.qcloud.tuikit.timcommon.manager.FileManager; import com.tencent.qcloud.tuikit.tuichat.R; import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo; import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity; import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity; import com.tencent.qcloud.tuikit.tuichat.custombean.fileupdate.HeaWorkFileUpdateBean; public class UpdateNotification { public static void createNotification(HeaWorkFileUpdateBean tuiMessageBean, ChatInfo chatInfo,int progress, int max) { long id=Long.valueOf(tuiMessageBean.getId()); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (TIMCommonService.getAppContext().getSystemService(NotificationManager.class).getNotificationChannel(id+"")==null){ NotificationChannel channel = new NotificationChannel(id+"", "upload", NotificationManager.IMPORTANCE_DEFAULT); channel.enableVibration(true); channel.setLightColor(Color.WHITE); channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC); TIMCommonService.getAppContext().getSystemService(NotificationManager.class).createNotificationChannel(channel); } } int percentage=(int) Math.ceil(Float.valueOf(progress) / Float.valueOf(max) * 100); RemoteViews remoteViews=new RemoteViews(TIMCommonService.getAppContext().getPackageName(),R.layout.notification_upload); remoteViews.setImageViewResource(R.id.iv_file_type, FileManager.getFileIcon(tuiMessageBean.getMessage().filePath)); remoteViews.setTextViewText(R.id.tv_file_name,"FileName:"+ tuiMessageBean.getMessage().fileName); remoteViews.setTextViewText(R.id.tv_receiver,"Receiver("+(tuiMessageBean.isGroup()?"GroupChat":"SingleChat")+"):"+chatInfo.getChatName()); remoteViews.setProgressBar(R.id.pb_upload_progress,max,progress,false ); remoteViews.setTextViewText(R.id.tv_upload_progress,""+percentage+"%" ); NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(TIMCommonService.getAppContext(), id+"") .setSmallIcon(R.drawable.app_logo)//通知图标 .setContentTitle(" ")//通知标题 .setContentText(" ")//通知内容 .setContent(remoteViews) .setCategory(NotificationCompat.CATEGORY_MESSAGE)//设置类别 .setPriority(NotificationCompat.PRIORITY_DEFAULT)//设置优先级 // .setVibrate(new long[]{0, 1000, 500, 1000})//设置振动 .setLights(Color.WHITE, 1000, 1000) .setContentIntent(gotoChat(tuiMessageBean,chatInfo)) .setAutoCancel(false);//设置点击通知自动关闭 NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(TIMCommonService.getAppContext()); if (ActivityCompat.checkSelfPermission( TIMCommonService.getAppContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { return; } notificationManagerCompat.notify((int)id, notificationCompat.build()); } public static PendingIntent gotoChat(HeaWorkFileUpdateBean tuiMessageBean,ChatInfo chatInfo){ Intent intent=new Intent(); Bundle bundle = new Bundle(); bundle.putInt(TUIConstants.TUIChat.CHAT_TYPE, chatInfo.getType()); bundle.putString(TUIConstants.TUIChat.CHAT_ID, chatInfo.getId()); bundle.putString(TUIConstants.TUIChat.CHAT_NAME, chatInfo.getChatName()); if (chatInfo.getDraft() != null) { bundle.putString(TUIConstants.TUIChat.DRAFT_TEXT, chatInfo.getDraft().getDraftText()); bundle.putLong(TUIConstants.TUIChat.DRAFT_TIME, chatInfo.getDraft().getDraftTime()); } bundle.putBoolean(TUIConstants.TUIChat.IS_TOP_CHAT, chatInfo.isTopChat()); if (chatInfo.getLocateMessage() != null && chatInfo.getLocateMessage().getV2TIMMessage() != null) { bundle.putSerializable(TUIConstants.TUIChat.LOCATE_MESSAGE, chatInfo.getLocateMessage().getV2TIMMessage()); } if (tuiMessageBean.isGroup()){ bundle.putString(TUIConstants.TUIChat.GROUP_TYPE, chatInfo.getGroupType()); intent.setClass(TIMCommonService.getAppContext(), TUIGroupChatActivity.class); }else { intent.setClass(TIMCommonService.getAppContext(), TUIC2CChatActivity.class); } intent.putExtras(bundle); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(TIMCommonService.getAppContext(), 2, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); return pendingIntent; } public static void clearNotification(TUIMessageBean tuiMessageBean){ long id=Long.valueOf(tuiMessageBean.getId()); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(TIMCommonService.getAppContext()); notificationManagerCompat.cancel((int)id); } } ```
``` package com.tencent.qcloud.tuikit.tuichat.notification; import android.Manifest; import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Color; import android.os.Bundle; import android.widget.RemoteViews; import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import com.huanqi.android.Utils.HQWLogUtil; import com.tencent.imsdk.v2.V2TIMConversation; import com.tencent.qcloud.tuicore.TUIConstants; import com.tencent.qcloud.tuicore.TUICore; import com.tencent.qcloud.tuikit.timcommon.TIMCommonService; import com.tencent.qcloud.tuikit.timcommon.bean.TUIMessageBean; import com.tencent.qcloud.tuikit.timcommon.manager.FileManager; import com.tencent.qcloud.tuikit.tuichat.R; import com.tencent.qcloud.tuikit.tuichat.bean.ChatInfo; import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIC2CChatActivity; import com.tencent.qcloud.tuikit.tuichat.classicui.page.TUIGroupChatActivity; import com.tencent.qcloud.tuikit.tuichat.custombean.fileupdate.HeaWorkFileUpdateBean; public class UpdateNotification { public static void createNotification(HeaWorkFileUpdateBean tuiMessageBean, ChatInfo chatInfo,int progress, int max) { long id=Long.valueOf(tuiMessageBean.getId()); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { if (TIMCommonService.getAppContext().getSystemService(NotificationManager.class).getNotificationChannel(id+"")==null){ NotificationChannel channel = new NotificationChannel(id+"", "upload", NotificationManager.IMPORTANCE_DEFAULT); channel.enableVibration(true); channel.setLightColor(Color.WHITE); channel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC); TIMCommonService.getAppContext().getSystemService(NotificationManager.class).createNotificationChannel(channel); } } int percentage=(int) Math.ceil(Float.valueOf(progress) / Float.valueOf(max) * 100); RemoteViews remoteViews=new RemoteViews(TIMCommonService.getAppContext().getPackageName(),R.layout.notification_upload); remoteViews.setImageViewResource(R.id.iv_file_type, FileManager.getFileIcon(tuiMessageBean.getMessage().filePath)); remoteViews.setTextViewText(R.id.tv_file_name,"FileName:"+ tuiMessageBean.getMessage().fileName); remoteViews.setTextViewText(R.id.tv_receiver,"Receiver("+(tuiMessageBean.isGroup()?"GroupChat":"SingleChat")+"):"+chatInfo.getChatName()); remoteViews.setProgressBar(R.id.pb_upload_progress,max,progress,false ); remoteViews.setTextViewText(R.id.tv_upload_progress,""+percentage+"%" ); NotificationCompat.Builder notificationCompat = new NotificationCompat.Builder(TIMCommonService.getAppContext(), id+"") .setSmallIcon(R.drawable.app_logo)//通知图标 .setContentTitle(" ")//通知标题 .setContentText(" ")//通知内容 .setContent(remoteViews) .setCategory(NotificationCompat.CATEGORY_MESSAGE)//设置类别 .setPriority(NotificationCompat.PRIORITY_DEFAULT)//设置优先级 // .setVibrate(new long[]{0, 1000, 500, 1000})//设置振动 .setLights(Color.WHITE, 1000, 1000) .setContentIntent(gotoChat(tuiMessageBean,chatInfo)) .setAutoCancel(false);//设置点击通知自动关闭 NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(TIMCommonService.getAppContext()); if (ActivityCompat.checkSelfPermission( TIMCommonService.getAppContext(), Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { return; } notificationManagerCompat.notify((int)id, notificationCompat.build()); } public static PendingIntent gotoChat(HeaWorkFileUpdateBean tuiMessageBean,ChatInfo chatInfo){ Intent intent=new Intent(); Bundle bundle = new Bundle(); bundle.putInt(TUIConstants.TUIChat.CHAT_TYPE, chatInfo.getType()); bundle.putString(TUIConstants.TUIChat.CHAT_ID, chatInfo.getId()); bundle.putString(TUIConstants.TUIChat.CHAT_NAME, chatInfo.getChatName()); if (chatInfo.getDraft() != null) { bundle.putString(TUIConstants.TUIChat.DRAFT_TEXT, chatInfo.getDraft().getDraftText()); bundle.putLong(TUIConstants.TUIChat.DRAFT_TIME, chatInfo.getDraft().getDraftTime()); } bundle.putBoolean(TUIConstants.TUIChat.IS_TOP_CHAT, chatInfo.isTopChat()); if (chatInfo.getLocateMessage() != null && chatInfo.getLocateMessage().getV2TIMMessage() != null) { bundle.putSerializable(TUIConstants.TUIChat.LOCATE_MESSAGE, chatInfo.getLocateMessage().getV2TIMMessage()); } if (tuiMessageBean.isGroup()){ bundle.putString(TUIConstants.TUIChat.GROUP_TYPE, chatInfo.getGroupType()); intent.setClass(TIMCommonService.getAppContext(), TUIGroupChatActivity.class); }else { intent.setClass(TIMCommonService.getAppContext(), TUIC2CChatActivity.class); } intent.putExtras(bundle); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(TIMCommonService.getAppContext(), 2, intent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE); return pendingIntent; } public static void clearNotification(TUIMessageBean tuiMessageBean){ long id=Long.valueOf(tuiMessageBean.getId()); NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(TIMCommonService.getAppContext()); notificationManagerCompat.cancel((int)id); } } ```
评论 (
0
)
黎明白昼
创建了
任务
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (2)
标签 (38)
master
demo
1.9.9
1.9.8
1.9.7
1.9.6
1.9.5
1.9.0
1.6.8
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.9
1.5.8
1.5.7
1.5.1
1.4.1
1.4.0
Beta1.3.7
1.3.6
1.3.5
1.3.4
1.3.3
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.1.7
1.1.6
1.1.5
1.1.2
1.1.1
1.0.9
1.0.8
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)
Android
1
https://gitee.com/BAILIS/HQW.git
[email protected]
:BAILIS/HQW.git
BAILIS
HQW
HQW
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册