Birden fazla reklam isteğini işleme
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
IMA SDK'sının çoğu kullanımında tek seferde yalnızca tek bir reklam isteğinin yönetilmesi gerekir. Ancak kullanıcı bir video seçmeden önce reklam verilerini ön yükleme gibi bazı uç durum uygulamaları, birden fazla eşzamanlı istek yapılmasını gerektirebilir. Reklam istekleri eşzamanlı olarak yapılmadığından, doğru reklam yöneticisinin doğru bağlamla ilişkilendirildiğinden emin olmak zor bir iş gibi görünebilir.
Android için IMA SDK'sı, birden fazla reklam yöneticisini ayırt etme sürecini basitleştirmek amacıyla yayıncıların herhangi bir reklam isteğinin UserRequestContext alanına herhangi bir değer veya nesne iletmesine olanak tanır. Bu değer veya nesne daha sonra AdsManagerLoadedEvent işleyicisinde getUserRequestContext() yöntemi kullanılarak alınabilir.
Örnek
...
adsLoader = sdkFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);
Map<String, String> userContextA = new HashMap<String, String>();
Map<String, String> userContextB = new HashMap<String, String>();
userContextA.put("id", "Request A");
userContextB.put("id", "Request B");
userContextA.put("element", "videoElementA");
userContextB.put("element", "videoElementB");
adRequestA.setUserRequestContext(userContextA);
adRequestB.setUserRequestContext(userContextB);
adsLoader.addAdsLoadedListener(
new AdsLoader.AdsLoadedListener() {
@Override
public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
Map<String, String> context = adsManagerLoadedEvent.getUserRequestContext();
adsManager = adsManagerLoadedEvent.getAdsManager();
Log.i("ImaExample", "Successfully loaded ID: " + context.get("id"));
}
});
adsLoader.addAdErrorListener(
new AdErrorEvent.AdErrorListener() {
@Override
public void onAdError(AdErrorEvent adErrorEvent) {
Map<String, String> context = adErrorEvent.getUserRequestContext();
Log.i("ImaExample", "Error with AdRequest. ID: " + context.get("id"));
Log.i("ImaExample", "Ad Error: " + adErrorEvent.getError().getMessage());
}
});
adsLoader.requestAds(adRequestA);
adsLoader.requestAds(adRequestB);
...
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-31 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-31 UTC."],[[["\u003cp\u003eThe IMA SDK for Android allows for managing multiple, concurrent ad requests by associating a unique context with each request.\u003c/p\u003e\n"],["\u003cp\u003ePublishers can use the \u003ccode\u003eUserRequestContext\u003c/code\u003e field of an ad request to pass in a custom identifier (e.g., a Map).\u003c/p\u003e\n"],["\u003cp\u003eThis identifier can then be retrieved in the \u003ccode\u003eAdsManagerLoadedEvent\u003c/code\u003e or \u003ccode\u003eAdErrorEvent\u003c/code\u003e handlers using \u003ccode\u003egetUserRequestContext()\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThis functionality simplifies the process of differentiating between ad managers tied to specific video content or elements.\u003c/p\u003e\n"]]],[],null,["# Handle multiple ad requests\n\nMost uses of the IMA SDK only require managing a single ad request at a time. However some edge case implementations, such as preloading ad data before the user selects a video, may require making multiple concurrent requests. Since ad requests are made asynchronously, ensuring the proper ad manager is associated with the correct context can seem to be a daunting task.\n\nTo simplify the process of differentiating multiple ad managers, the IMA SDK for Android allows publishers to pass in any value or object to the [UserRequestContext](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsRequest.html#public-abstract-void-setuserrequestcontext-object-userrequestcontext) field of any ad request. This value or object can then be retrieved in the [AdsManagerLoadedEvent](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsManagerLoadedEvent) handler, by using the method [getUserRequestContext()](https://developers.google.com/interactive-media-ads/docs/sdks/android/dai/api/reference/com/google/ads/interactivemedia/v3/api/AdsManagerLoadedEvent.html#public-abstract-object-getuserrequestcontext).\n\nExample\n-------\n\n ...\n\n adsLoader = sdkFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);\n\n Map\u003cString, String\u003e userContextA = new HashMap\u003cString, String\u003e();\n Map\u003cString, String\u003e userContextB = new HashMap\u003cString, String\u003e();\n userContextA.put(\"id\", \"Request A\");\n userContextB.put(\"id\", \"Request B\");\n userContextA.put(\"element\", \"videoElementA\");\n userContextB.put(\"element\", \"videoElementB\");\n adRequestA.setUserRequestContext(userContextA);\n adRequestB.setUserRequestContext(userContextB);\n\n adsLoader.addAdsLoadedListener(\n new AdsLoader.AdsLoadedListener() {\n @Override\n public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {\n Map\u003cString, String\u003e context = adsManagerLoadedEvent.getUserRequestContext();\n adsManager = adsManagerLoadedEvent.getAdsManager();\n Log.i(\"ImaExample\", \"Successfully loaded ID: \" + context.get(\"id\"));\n }\n });\n\n adsLoader.addAdErrorListener(\n new AdErrorEvent.AdErrorListener() {\n @Override\n public void onAdError(AdErrorEvent adErrorEvent) {\n Map\u003cString, String\u003e context = adErrorEvent.getUserRequestContext();\n Log.i(\"ImaExample\", \"Error with AdRequest. ID: \" + context.get(\"id\"));\n Log.i(\"ImaExample\", \"Ad Error: \" + adErrorEvent.getError().getMessage());\n }\n });\n\n adsLoader.requestAds(adRequestA);\n adsLoader.requestAds(adRequestB);\n\n ..."]]