Android Facebook Native Ads with Cursor and ads Video Crashing

时间:2015-09-14 15:53:53

标签: android facebook facebook-android-sdk facebook-audience-network

I integrated facebook native ads in my android app referring the official docs: https://developers.facebook.com/docs/audience-network/android/native-api.

I have 2 questions:

1) Implementation Advice:

This is how I implemented it.

  • My RecyclerView is attached to a cursor as data source.
  • Each row of cursor has a 'type' column.

  • Based on the 'type' parameter view of each row item is decided in getItemViewType(position) method of the RecyclerView.

  • I cache facebook native ads in a Hashmap with the key set to nativeAd.getId().

  • Caching is done using Facebooks NativeAdsManager.

  • When my rows 'type' is 'ads' then I search the Hashmap for that ads id. Retrieve that ad from Hashmap and display ad view accordingly.

The above implementation works smoothly(most of the time). My question is, how efficient is this implementation? (Do suggest me your ways if you have implemented fb native ads with cursor as data source)

2) Facebook Ads Crash

To display a native ad I use MediaView as suggested by Facebook in the documentation (https://developers.facebook.com/docs/audience-network/android/native-api) to show the ads cover picture.

It works normally while displaying photos but have a unpredictable behavior while displaying video ads. Some video ads crash the app with the following exception:

09-14 20:31:00.306  13492-13492/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example, PID: 13492
java.lang.IllegalStateException
        at android.media.MediaPlayer._getCurrentPosition(Native Method)
        at android.media.MediaPlayer.getCurrentPosition(MediaPlayer.java:1888)
        at com.facebook.ads.internal.view.video.support.d.getCurrentPosition(Unknown Source)
        at com.facebook.ads.internal.view.video.support.a.getCurrentPosition(Unknown Source)
        at com.facebook.ads.internal.view.video.a$2.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5633)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
        at dalvik.system.NativeStart.main(Native Method)

Have no clue on this one, any help would be appreciated. Thanks.

0 个答案:

没有答案