Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-api
提交
de23c355
U
uni-api
项目概览
DCloud
/
uni-api
通知
670
Star
23
Fork
12
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-api
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
de23c355
编写于
11月 30, 2023
作者:
taohebin@dcloud.io
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: uni-progress-notification createNotificationProgress增加onClick
上级
fc2cfbf1
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
103 addition
and
63 deletion
+103
-63
uni_modules/uni-progress-notification/changelog.md
uni_modules/uni-progress-notification/changelog.md
+5
-0
uni_modules/uni-progress-notification/package.json
uni_modules/uni-progress-notification/package.json
+1
-1
uni_modules/uni-progress-notification/readme.md
uni_modules/uni-progress-notification/readme.md
+7
-2
uni_modules/uni-progress-notification/utssdk/app-android/TransparentActivity.uts
...s-notification/utssdk/app-android/TransparentActivity.uts
+48
-35
uni_modules/uni-progress-notification/utssdk/app-android/index.uts
...es/uni-progress-notification/utssdk/app-android/index.uts
+30
-21
uni_modules/uni-progress-notification/utssdk/interface.uts
uni_modules/uni-progress-notification/utssdk/interface.uts
+12
-4
未找到文件。
uni_modules/uni-progress-notification/changelog.md
浏览文件 @
de23c355
## 1.0.4(2023-11-30)
1.
createNotificationProgress增加
`onClick`
回调
2.
修复在小米部分系统上,通知消息会归类于不重要通知的bug
## 1.0.3(2023-11-28)
更新截图
## 1.0.2(2023-11-28)
## 1.0.2(2023-11-28)
修改资源的包名
修改资源的包名
## 1.0.1(2023-11-28)
## 1.0.1(2023-11-28)
...
...
uni_modules/uni-progress-notification/package.json
浏览文件 @
de23c355
{
{
"id"
:
"uni-progress-notification"
,
"id"
:
"uni-progress-notification"
,
"displayName"
:
"uni-progress-notification"
,
"displayName"
:
"uni-progress-notification"
,
"version"
:
"1.0.
2
"
,
"version"
:
"1.0.
4
"
,
"description"
:
"uni-progress-notification"
,
"description"
:
"uni-progress-notification"
,
"keywords"
:
[
"keywords"
:
[
"uni-progress-notification"
"uni-progress-notification"
...
...
uni_modules/uni-progress-notification/readme.md
浏览文件 @
de23c355
...
@@ -26,7 +26,12 @@ export type CreateNotificationProgressOptions = {
...
@@ -26,7 +26,12 @@ export type CreateNotificationProgressOptions = {
/**
/**
* 进度
* 进度
*/
*/
progress : number
progress : number,
/**
* 点击通知消息回调
* @defaultValue null
*/
onClick? : (() => void) | null
}
}
```
```
...
@@ -51,7 +56,7 @@ export type FinishNotificationProgressOptions = {
...
@@ -51,7 +56,7 @@ export type FinishNotificationProgressOptions = {
/**
/**
* 点击通知消息回调
* 点击通知消息回调
*/
*/
callba
ck : () => void
onCli
ck : () => void
}
}
```
```
...
...
uni_modules/uni-progress-notification/utssdk/app-android/TransparentActivity.uts
浏览文件 @
de23c355
...
@@ -4,8 +4,8 @@ import Build from 'android.os.Build';
...
@@ -4,8 +4,8 @@ import Build from 'android.os.Build';
import View from 'android.view.View';
import View from 'android.view.View';
import Color from 'android.graphics.Color';
import Color from 'android.graphics.Color';
import WindowManager from 'android.view.WindowManager';
import WindowManager from 'android.view.WindowManager';
import { globalNotificationProgressFinishCallBack } from './index.uts';
import { globalNotificationProgressFinishCallBack
, globalNotificationProgressCallBack
} from './index.uts';
import { ACTION_DOWNLOAD_FINISH } from "./constant.uts"
import { ACTION_DOWNLOAD_FINISH
, ACTION_DOWNLOAD_PROGRESS
} from "./constant.uts"
export class TransparentActivity extends Activity {
export class TransparentActivity extends Activity {
...
@@ -18,7 +18,18 @@ export class TransparentActivity extends Activity {
...
@@ -18,7 +18,18 @@ export class TransparentActivity extends Activity {
this.fullScreen(this)
this.fullScreen(this)
const action = this.getIntent().getAction()
const action = this.getIntent().getAction()
if (action == ACTION_DOWNLOAD_FINISH) {
if (action == ACTION_DOWNLOAD_FINISH) {
setTimeout(() => {
globalNotificationProgressFinishCallBack()
globalNotificationProgressFinishCallBack()
globalNotificationProgressFinishCallBack = () => { }
}, 100)
this.overridePendingTransition(0, 0)
}
if (action == ACTION_DOWNLOAD_PROGRESS) {
setTimeout(() => {
globalNotificationProgressCallBack?.()
globalNotificationProgressCallBack = () => { }
}, 100)
this.overridePendingTransition(0, 0)
this.overridePendingTransition(0, 0)
}
}
...
@@ -27,6 +38,8 @@ export class TransparentActivity extends Activity {
...
@@ -27,6 +38,8 @@ export class TransparentActivity extends Activity {
}, 20)
}, 20)
}
}
@Suppress("DEPRECATION")
private fullScreen(activity : Activity) {
private fullScreen(activity : Activity) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 19) {
if (Build.VERSION.SDK_INT >= 21) {
if (Build.VERSION.SDK_INT >= 21) {
...
...
uni_modules/uni-progress-notification/utssdk/app-android/index.uts
浏览文件 @
de23c355
...
@@ -7,7 +7,7 @@ import Intent from 'android.content.Intent';
...
@@ -7,7 +7,7 @@ import Intent from 'android.content.Intent';
import ComponentName from 'android.content.ComponentName';
import ComponentName from 'android.content.ComponentName';
import PendingIntent from 'android.app.PendingIntent';
import PendingIntent from 'android.app.PendingIntent';
import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS
} from "./constant.uts"
import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS
} from "./constant.uts"
export { TransparentActivity } from './TransparentActivity.uts';
export { TransparentActivity } from './TransparentActivity.uts';
...
@@ -26,11 +26,17 @@ let histroyProgress = 0
...
@@ -26,11 +26,17 @@ let histroyProgress = 0
let isProgress = false
let isProgress = false
export let globalNotificationProgressCallBack : (() => void) | null = () => { }
export let globalNotificationProgressFinishCallBack = () => { }
export let globalNotificationProgressFinishCallBack = () => { }
export function createNotificationProgress(options : CreateNotificationProgressOptions) : void {
export function createNotificationProgress(options : CreateNotificationProgressOptions) : void {
const { content, progress } = options
const { content, progress, onClick } = options
if (progress == 100) {
if (progress == 100) {
clearTimeout(timeId)
const context = UTSAndroid.getAppContext() as Context
realCreateNotificationProgress(options.title ?? getAppName(context), content, progress, onClick)
reset()
return
return
}
}
...
@@ -41,11 +47,11 @@ export function createNotificationProgress(options : CreateNotificationProgressO
...
@@ -41,11 +47,11 @@ export function createNotificationProgress(options : CreateNotificationProgressO
const context = UTSAndroid.getAppContext() as Context
const context = UTSAndroid.getAppContext() as Context
if (!isProgress) {
if (!isProgress) {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress)
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress
, onClick
)
isProgress = true
isProgress = true
} else {
} else {
timeId = setTimeout(() => {
timeId = setTimeout(() => {
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress)
realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress
, onClick
)
timeId = -1
timeId = -1
}, 1000)
}, 1000)
}
}
...
@@ -60,7 +66,8 @@ export function cancelNotificationProgress() : void {
...
@@ -60,7 +66,8 @@ export function cancelNotificationProgress() : void {
}
}
function realCreateNotificationProgress(title : string, content : string, progress : number) : void {
function realCreateNotificationProgress(title : string, content : string, progress : number, cb : (() => void) | null) : void {
globalNotificationProgressCallBack = cb
const context = UTSAndroid.getAppContext() as Context
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
createDownloadChannel(notificationManager)
...
@@ -74,7 +81,7 @@ function realCreateNotificationProgress(title : string, content : string, progre
...
@@ -74,7 +81,7 @@ function realCreateNotificationProgress(title : string, content : string, progre
export function finishNotificationProgress(options : FinishNotificationProgressOptions) {
export function finishNotificationProgress(options : FinishNotificationProgressOptions) {
globalNotificationProgressFinishCallBack = options.
callba
ck
globalNotificationProgressFinishCallBack = options.
onCli
ck
const context = UTSAndroid.getAppContext() as Context
const context = UTSAndroid.getAppContext() as Context
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
createDownloadChannel(notificationManager)
createDownloadChannel(notificationManager)
...
@@ -82,7 +89,8 @@ export function finishNotificationProgress(options : FinishNotificationProgressO
...
@@ -82,7 +89,8 @@ export function finishNotificationProgress(options : FinishNotificationProgressO
builder.setProgress(0, 0, false)
builder.setProgress(0, 0, false)
builder.setContentTitle(options.title ?? getAppName(context))
builder.setContentTitle(options.title ?? getAppName(context))
builder.setContentText(options.content)
builder.setContentText(options.content)
builder.setOngoing(false)
//小米rom setOngoing未false的时候,会被通知管理器归为不重要通知
// builder.setOngoing(false)
builder.setAutoCancel(true);
builder.setAutoCancel(true);
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
...
@@ -122,7 +130,7 @@ function createDownloadChannel(notificationManager : NotificationManager) {
...
@@ -122,7 +130,7 @@ function createDownloadChannel(notificationManager : NotificationManager) {
notificationManager.createNotificationChannel(channel)
notificationManager.createNotificationChannel(channel)
}
}
}
}
@Suppress("DEPRECATION")
function createNotificationBuilder(context : Context) : Notification.Builder {
function createNotificationBuilder(context : Context) : Notification.Builder {
if (notificationBuilder == null) {
if (notificationBuilder == null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
...
@@ -130,13 +138,14 @@ function createNotificationBuilder(context : Context) : Notification.Builder {
...
@@ -130,13 +138,14 @@ function createNotificationBuilder(context : Context) : Notification.Builder {
} else {
} else {
notificationBuilder = new Notification.Builder(context)
notificationBuilder = new Notification.Builder(context)
}
}
notificationBuilder!
!
.setSmallIcon(context.getApplicationInfo().icon)
notificationBuilder!.setSmallIcon(context.getApplicationInfo().icon)
notificationBuilder!
!
.setOngoing(true)
notificationBuilder!.setOngoing(true)
notificationBuilder!
!
.setSound(null)
notificationBuilder!.setSound(null)
}
}
return notificationBuilder!
!
return notificationBuilder!
}
}
@Suppress("DEPRECATION")
function getAppName(context : Context) : string {
function getAppName(context : Context) : string {
let appName = ""
let appName = ""
try {
try {
...
...
uni_modules/uni-progress-notification/utssdk/interface.uts
浏览文件 @
de23c355
...
@@ -24,7 +24,10 @@ export type uni = {
...
@@ -24,7 +24,10 @@ export type uni = {
uni.createNotificationProgress({
uni.createNotificationProgress({
title: "正在下载升级包",
title: "正在下载升级包",
content: "进度 50%",
content: "进度 50%",
progress: 50
progress: 50,
onClick:()=>{
console.log("正在下载");
}
}
}
```
```
*/
*/
...
@@ -54,7 +57,7 @@ export type uni = {
...
@@ -54,7 +57,7 @@ export type uni = {
uni.finishNotificationProgress({
uni.finishNotificationProgress({
title: "安装升级包",
title: "安装升级包",
content: "下载完成。",
content: "下载完成。",
callba
ck: () => {
onCli
ck: () => {
uni.installApk({
uni.installApk({
filePath: e.tempFilePath,
filePath: e.tempFilePath,
complete(res) {
complete(res) {
...
@@ -107,7 +110,12 @@ export type CreateNotificationProgressOptions = {
...
@@ -107,7 +110,12 @@ export type CreateNotificationProgressOptions = {
/**
/**
* 进度
* 进度
*/
*/
progress : number
progress : number,
/**
* 点击通知消息回调
* @defaultValue null
*/
onClick? : (() => void) | null
}
}
...
@@ -124,7 +132,7 @@ export type FinishNotificationProgressOptions = {
...
@@ -124,7 +132,7 @@ export type FinishNotificationProgressOptions = {
/**
/**
* 点击通知消息回调
* 点击通知消息回调
*/
*/
callba
ck : () => void
onCli
ck : () => void
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录