HarmonyOS鸿蒙Next中【快应用】adbutton如何直接下载广告而不跳落地页再下载

HarmonyOS鸿蒙Next中【快应用】adbutton如何直接下载广告而不跳落地页再下载 【关键词】

原生广告、adbutton、下载

【问题背景】

快应用中的原生广告推出了adbutton组件来直接下载广告app,在使用的时候,点击adbutton按钮的安装文案,不是直接下载广告app,而是跳转到落地页后直接下载,这种情形该如何解决?

相关代码:

import ad from '@service.ad'
let nativeAd
export default {
  componentName: 'ad',
  provider: '',
  data: {
    native: {
      adUnitId: 'testb65czjivt9',
      isShow: 'false',
      adData: {},
      isShowImg: false,
      isShowVideo: false,
      isShowData: false,
      isShowDesc: false,
      errStr: '',
      adImgSrc: '',
      adImgSrc1: '',
      adImgSrc2: '',
      adVideoSrc: ''
    }
  },
  hideAll() {
    this.native.isShow = false
    this.native.isShowImg = false
    this.native.isShowVideo = false
    this.native.isShowDesc = false
  },
  showNativeAd() {
    nativeAd = ad.createNativeAd({ adUnitId: this.native.adUnitId })
    nativeAd.onLoad((data) => {
      console.info('ad data loaded: ' + JSON.stringify(data))
      this.native.adData = data.adList[0]
      if (this.native.adData) {
        if (this.native.adData.imgUrlList) {
          this.native.adImgSrc = this.native.adData.imgUrlList[0]
          this.native.isShowImg = true
        } else {
          this.native.isShowImg = false
          this.native.adImgSrc = ''
        }
        if (this.native.adData.desc) {
          this.native.desc = this.native.adData.desc
          this.native.isShowDesc = true
        }
        let showVideoFlag = false
        if (this.native.adData.videoUrlList && this.native.adData.videoUrlList[0]) {
          this.native.adVideoSrc = this.native.adData.videoUrlList[0]
          showVideoFlag = true
        } else {
          this.native.isShowVideo = false
          this.native.adVideoSrc = ''
        }
        if (this.native.isShowImg && showVideoFlag) {
          setTimeout(() => {
            this.native.isShowVideo = true
            this.native.isShowImg = false
          }, 1000)
        }
      }
      this.native.isShow = true
      this.native.errStr = ''
    })
    nativeAd.onError((e) => {
      console.error('load ad error:' + JSON.stringify(e))
      this.native.isShowImg = false
      this.native.isShowVideo = false
    })
    nativeAd.load()
  },
  reportNativeClick() {
    nativeAd.reportAdClick({
      'adId': this.native.adData.adId
    })
  },
  setProductIdValue: function (e) {
    this.native.adUnitId = e.value
  },
  onAdButtonClick(event) {
    console.error('result code is : ', event.resultCode)
    nativeAd.reportAdClick({
      'adId': this.native.adData.adId
    })
  }
}

【问题分析】

可以看到adbutton的点击事件是onAdButtonClick控制的,在点击时进行了一个上报广告点击,看起来是没有任何问题的。实则是不对的因为该接口除了一个上报广告点击的功能外,还有一个额外的作用就是跳转到广告落地页,这个我们可以在原生广告使用时就可以看出来。

再看下adbutton的描述:

描述里是用来下载广告主app的,所以当在adbutton点击后调用reportadclick进行上报的时候看到的就是跳转落地页并下载了。

【解决方法】

去掉adbutton中的上报广告点击调用,此按钮是用来进行下载和打开广告主app的。


更多关于HarmonyOS鸿蒙Next中【快应用】adbutton如何直接下载广告而不跳落地页再下载的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于HarmonyOS鸿蒙Next中【快应用】adbutton如何直接下载广告而不跳落地页再下载的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,【快应用】的adbutton组件默认会跳转到广告落地页后再进行下载。若需直接下载广告而不跳转,可以通过以下步骤实现:

  1. 获取广告信息:使用adbuttononAdShow事件获取广告的下载链接。
  2. 直接下载:通过fetchdownload API直接下载广告内容,绕过落地页跳转。

示例代码:

adbutton.onAdShow((adInfo) => {
  const downloadUrl = adInfo.downloadUrl;
  downloadFile(downloadUrl);
});

function downloadFile(url) {
  // 使用fetch或download API进行下载
}

注意:直接下载可能违反广告平台政策,需确保合规性。

回到顶部