Skip to content

创建通知通道

安卓8.0以上的应用需要在客户端主动创建NotificaitonChannel

注意

建议调用该方法,插件内部已自动判断是否是安卓8.0以上设备,如果安卓8.0以下插件会默认跳过创建NotificaitonChannel,设置的默认参数也将无效

方法名

createNotificationChannel

用法

  • 用法如下:
js
module.createNotificationChannel({
  params: {
    channelId: "",
    name:"",
    description:"",
    importance:"IMPORTANCE_HIGH",
    enableLights:true,
    lightColor:"#FF0000",
    enableVibration:true,
    sound:"",
    vibrationPattern:[100, 200, 300, 400, 500, 400, 300, 200, 400]
  },
  //成功执行的函数
  success: (res) => {
    console.log(data)
  },
  //失败执行的函数
  fail: (res) => {
    console.log(res)
  },
  //接口调用完成返回函数,不管成功还是失败都会返回
  complete: (res) => {
    // console.log(res)
  }
})
js
module.createNotificationChannel({
  params: {
    channelId: "",
    name:"",
    description:"",
    importance:"IMPORTANCE_HIGH",
    enableLights:true,
    lightColor:"#FF0000",
    enableVibration:true,
    sound:"",
    vibrationPattern:[100, 200, 300, 400, 500, 400, 300, 200, 400]
  },
  //成功执行的函数
  success: (res) => {
    console.log(res)
  },
  //失败执行的函数
  fail: (res) => {
    console.log(res)
  },
  //接口调用完成返回函数,不管成功还是失败都会返回
  // complete: (res) => {
  //   console.log(res)
  // }
} as LevenOptions)
  • 参数说明
    参数名参数类型是否必填默认值参数描述
    paramsObject接口请求参数
    params.channelIdString渠道id
    params.nameString通知渠道的名字
    params.descriptionString通知渠道的描述
    params.importanceStringIMPORTANCE_HIGH通知渠道的重要等级,可选值:IMPORTANCE_HIGH IMPORTANCE_NONE IMPORTANCE_MIN IMPORTANCE_LOW IMPORTANCE_DEFAULT IMPORTANCE_MAX IMPORTANCE_UNSPECIFIED
    params.enableLightsBoolean设置通知出现时的闪灯(如果Android设备支持的话)
    params.lightColorString闪灯颜色
    params.enableVibrationBoolean设置通知出现时的震动(如果Android设备支持的话)
    params.soundString自定义铃声,铃声文件须放置到app-android > res > raw目录下,如果插件中没有该目录需创建一个,sound参数无需带扩展名
    params.vibrationPatternlong[]自定义震动序列
    successFunction执行成功的函数
    failFunction执行失败的函数
    completeFunction执行完成的函数,不管成功还是失败都会执行

回调

  • 示例
json
{
    "data": {},
    "message": "",
    "code": 0
}
  • 回调说明:
    参数名参数类型参数描述
    messageString消息提示
    dataObject数据对象
    codeInteger返回类型,0.成功,其他:失败