Я следовал инструкциям Mopub, чтобы внедрить их нативную рекламу в мое приложение для Android.
Я проверил код с другими источниками и, похоже, все в порядке, но на самом деле я не могу заставить Mopub загрузить какую-либо рекламу. Мой код:
SdkConfiguration sdkConfiguration = new SdkConfiguration
.Builder("11a17b188668469fb0412708c3d16813") // trial #
.build();
MoPub.initializeSdk(this, sdkConfiguration, initSdkListener());
MoPubNative moPubNative = new MoPubNative(this, "11a17b188668469fb0412708c3d16813", this); // 11a17b188668469fb0412708c3d16813
ViewBinder viewBinder = new ViewBinder.Builder(R.layout.mopub_native_ad_list_item)
.mainImageId(R.id.native_main_image)
.iconImageId(R.id.native_icon_image)
.titleId(R.id.native_title)
.textId(R.id.native_text)
.privacyInformationIconImageId(R.id.native_privacy_information_icon_image)
.build();
MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer(viewBinder);
moPubNative.registerAdRenderer(moPubStaticNativeAdRenderer);
EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of( // Optional
RequestParameters.NativeAdAsset.TITLE,
RequestParameters.NativeAdAsset.TEXT,
RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT,
RequestParameters.NativeAdAsset.MAIN_IMAGE,
RequestParameters.NativeAdAsset.ICON_IMAGE,
RequestParameters.NativeAdAsset.STAR_RATING
);
// RequestParameters mRequestParameters = new RequestParameters.Builder().desiredAssets(desiredAssets).build();
moPubNative.makeRequest();
И код обратных вызовов:
private SdkInitializationListener initSdkListener() {
return new SdkInitializationListener() {
@Override
public void onInitializationFinished() {
/* MoPub SDK initialized.
Check if you should show the consent dialog here, and make your ad requests. */
}
};
}
@Override
public void onNativeLoad(final com.mopub.nativeads.NativeAd nativeAd) {
FrameLayout mopubGloFrameLayout = (FrameLayout) findViewById(R.id.flurrymainframe); // Parent where to attach the Native Ad
View adView = nativeAd.createAdView(getBaseContext(), mopubGloFrameLayout);
nativeAd.prepare(adView);
nativeAd.renderAdView(adView);
mopubGloFrameLayout.addView(adView);
}
@Override
public void onNativeFail(final NativeErrorCode errorCode) {
Log.w(this.getClass().getSimpleName(), errorCode.toString());
}
@Override
public void onImpression(final View view) {
// Ad impression has been recorded on MoPub and the corresponding ad network
}
@Override
public void onClick(final View view) {
// Ad click has been recorded on MoPub and the corresponding ad network
}
И снимок собственных переменных MoPub после moPubNative.makeRequest ():
Мой соответствующий logcat:
01-21 03:36:13.534 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: GOOGLE PLAY SERVICES ERROR: java.util.concurrent.TimeoutException: Timed out waiting for the service connection
01-21 03:36:13.535 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.
01-21 03:36:23.539 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: GOOGLE PLAY SERVICES ERROR: java.util.concurrent.TimeoutException: Timed out waiting for the service connection
01-21 03:36:23.539 3936-3979/com.languagematerial.lmmovies E/FlurryAgent: There is a problem with the Google Play Services library, which is required for Android Advertising ID support. The Google Play Services library should be integrated in any app shipping in the Play Store that uses analytics or advertising.
01-21 03:36:26.405 3936-3936/com.languagematerial.lmmovies D/MoPub: Initializing MoPub with ad unit: 11a17b188668469fb0412708c3d16813
01-21 03:36:26.425 3936-3936/com.languagematerial.lmmovies D/MoPub: MoPubNative Loading ad from: https://ads.mopub.com/m/ad?id=11a17b188668469fb0412708c3d16813&nv=5.4.1&dn=unknown%2CAndroid%20SDK%20built%20for%20x86%
2Csdk_google_phone_x86&bundle=com.languagematerial.lmmovies&z=-0500&o=l&w=1024&h=600&sc=1.0&mcc=310&mnc=260&cn=Android&ct=6&av=1.0&udid=mp_tmpl_advertising_id&dnt=mp_tmpl_do_not_track&gdpr_applies=0&force_gdpr_applies=0¤t_consent_status=unknown
01-21 03:36:26.427 3936-3936/com.languagematerial.lmmovies E/MoPub: Make sure to call MoPub#initializeSdk before loading an ad.
01-21 03:36:26.437 3936-4009/com.languagematerial.lmmovies E/Volley: [236] NetworkDispatcher.processRequest: Unhandled exception java.lang.RuntimeException: Bad URL
java.lang.RuntimeException: Bad URL
at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.mopub.volley.toolbox.HurlStack.executeRequest(HurlStack.java:92)
at com.mopub.network.RequestQueueHttpStack.executeRequest(RequestQueueHttpStack.java:57)
at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
01-21 03:36:26.449 1263-1686/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
01-21 03:36:26.449 3936-4015/com.languagematerial.lmmovies D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
01-21 03:36:26.453 3936-3967/com.languagematerial.lmmovies W/chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup
01-21 03:36:26.456 3936-3936/com.languagematerial.lmmovies W/TextToSpeech: speak failed: not bound to TTS engine
01-21 03:36:26.456 3936-3936/com.languagematerial.lmmovies I/TextToSpeech: Connected to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
01-21 03:36:26.461 3936-4016/com.languagematerial.lmmovies I/TextToSpeech: Set up connection to ComponentInfo{com.svox.pico/com.svox.pico.PicoService}
01-21 03:36:26.488 3936-3936/com.languagematerial.lmmovies W/TextToSpeech: speak failed: TTS engine connection not fully set up
01-21 03:36:26.488 3936-3936/com.languagematerial.lmmovies D/MoPub: Native ad request failed.
com.mopub.network.MoPubNetworkError: java.lang.RuntimeException: Bad URL
at com.mopub.network.AdLoader.deliverError(AdLoader.java:275)
at com.mopub.network.AdLoader.access$200(AdLoader.java:30)
at com.mopub.network.AdLoader$1.onErrorResponse(AdLoader.java:85)
at com.mopub.volley.Request.deliverError(Request.java:630)
at com.mopub.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:108)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.RuntimeException: Bad URL
at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:171)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
Caused by: java.net.MalformedURLException: Protocol not found:
at java.net.URL.<init>(URL.java:176)
at java.net.URL.<init>(URL.java:125)
at com.mopub.volley.toolbox.HurlStack.executeRequest(HurlStack.java:92)
at com.mopub.network.RequestQueueHttpStack.executeRequest(RequestQueueHttpStack.java:57)
at com.mopub.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131)
at com.mopub.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120)
at com.mopub.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
01-21 03:36:26.489 3936-3936/com.languagematerial.lmmovies W/LMMoviesMainActivity: Unspecified error occurred.
01-21 03:36:26.490 3936-4006/com.languagematerial.lmmovies D/MoPub: MoPubIdentifier initialized.
01-21 03:36:26.491 3936-4010/com.languagematerial.lmmovies D/MoPub: Posting AsyncTask to main thread for execution.
Обратите внимание, что я получаю это предупреждение:
Обязательно вызовите MoPub # initializeSdk перед загрузкой рекламы.
В соответствии с переменными в снимке, мне удалось что-то загрузить, так почему он говорит, что нет?
Я просто не знаю, что еще делать. Есть аналогичные случаи сбоя MoPub Native в стековом потоке, но на самом деле ни один из них не предлагает никакого решения, даже альтернативы, чтобы приблизить его. И MoPub псевдоподдержка отстой. Вы успешно внедрили MoPub Native Ads? Если да, вы видите, что может быть не так с моим кодом? Спасибо