You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于gms:play-service:19.0.1,如何将应用中激励视频广告时长设置为30秒

Can't Set Rewarded Video Ad Duration via Code? Here's What You Need to Know

Hey there! Let me clear this up for you right away—you can’t directly set the duration of rewarded video ads using code with gms:play-services:19.0.1 (or any version of Google Play Services for that matter). Here’s why, and what you can do to work around this:

Core Reason

The length of rewarded video ads is determined entirely by the ad inventory from Google AdMob (or your chosen ad platform). Advertisers upload ads of varying durations, and the platform matches the most relevant ad to your app and user based on targeting rules. There’s no API or code setting that lets developers force a specific ad length.

Why You’re Seeing 10-Second Ads

Chances are, you’re either:

  • Using test ads: AdMob’s test ad units often serve short, sample ads (like 10 seconds) for development purposes. These don’t reflect the actual ad durations you’ll see in production.
  • Getting matched to short-duration ads in your current inventory: Depending on your app’s category, user demographics, or regional ad supply, shorter ads might be more prevalent right now.

Steps to Get Longer Ads

While you can’t code a fixed 30-second duration, you can optimize your setup to increase the likelihood of longer ads:

  • Switch to a production ad unit: Replace your test ad ID with your official rewarded video ad unit ID from the AdMob dashboard. Production ads will have a wider range of durations.
  • Verify your ad unit configuration: Double-check that your ad unit is set to "Rewarded Video" (not a shorter format like Rewarded Interstitial, which sometimes has shorter creatives).
  • Adjust ad mediation settings (if used): If you’re using AdMob Mediation to pull ads from multiple networks, you can prioritize ad sources that typically offer longer rewarded videos in the AdMob dashboard.
  • Reach out to AdMob support: If your app’s use case specifically requires longer ads (e.g., a reward tied to watching a full 30-second ad), you can contact AdMob support to discuss your needs—they may be able to adjust your ad targeting settings.

Example Code for Correct Ad Loading (19.0.1 Version)

Just to ensure your ad implementation is solid (even though it won’t control duration), here’s a snippet for loading and showing rewarded ads with your version:

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.rewarded.RewardedAd;
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
import com.google.android.gms.ads.rewarded.OnUserEarnedRewardListener;
import com.google.android.gms.ads.rewarded.RewardItem;

// Initialize RewardedAd object
private RewardedAd rewardedAd;

// Method to load the ad
private void loadRewardedAd() {
    AdRequest adRequest = new AdRequest.Builder().build();
    // Replace the test ID with your production ad unit ID
    String adUnitId = "ca-app-pub-3940256099942544/5224354917";
    
    RewardedAd.load(this, adUnitId, adRequest, new RewardedAdLoadCallback() {
        @Override
        public void onAdLoaded(RewardedAd ad) {
            rewardedAd = ad;
            // Ad is ready to show
        }

        @Override
        public void onAdFailedToLoad(com.google.android.gms.ads.LoadAdError loadAdError) {
            rewardedAd = null;
            // Handle ad load failure
        }
    });
}

// Method to show the ad when ready
private void showRewardedAd() {
    if (rewardedAd != null) {
        rewardedAd.show(this, new OnUserEarnedRewardListener() {
            @Override
            public void onUserEarnedReward(RewardItem rewardItem) {
                // Grant user reward here
            }
        });
    }
}

Important Note

Never try to manipulate ad playback (e.g., forcing a minimum duration or skipping ads early) to meet your needs—this violates AdMob’s program policies and could result in your account being suspended.

内容的提问来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 04:44:05