我正在尝试在我的应用中实现 Tapjoy 奖励视频,但它们没有出现。
private var directPlayPlacement: TJPlacement? = null
private var TJlistener: TJPlacementListener? = null
这是我的 initTapJoy() 函数:
fun initTapJoy() {
val connectFlags: Hashtable<String, Any> = Hashtable<String, Any>()
connectFlags[TapjoyConnectFlag.ENABLE_LOGGING] = "true";
connectFlags[TapjoyConnectFlag.USER_ID] = AppPreferences.token;
val callbackTJ = object : TJConnectListener {
override fun onConnectSuccess() {
this.tapJoyConnectSuccess()
Timber.d(TAG, "TapJoy SDK connected");
}
override fun onConnectFailure() {
Timber.d(TAG, "TapJoy SDK not connected");
}
fun tapJoyConnectSuccess() {
Tapjoy.setActivity(activity);
Tapjoy.setUserID(AppPreferences.token);
directPlayPlacement = Tapjoy.getPlacement("RewardedVideo", TJlistener)
TJlistener = object : TJPlacementListener {
override fun onRequestSuccess(p0: TJPlacement?) {
if (p0 != null) {
Timber.i("Tapjoy on request success, contentAvailable: %s", p0.isContentAvailable)
} else {
initTapJoy()
}
}
override fun onRequestFailure(p0: TJPlacement?, p1: TJError?) {
//activity.toast(getString(R.string.adds_content_empty))
Log.d(TAG,"onRequestFailure")
}
override fun onContentReady(p0: TJPlacement?) {}
override fun onContentShow(p0: TJPlacement?) {}
override fun onContentDismiss(p0: TJPlacement?) {
initTapJoy()
}
override fun onPurchaseRequest(p0: TJPlacement?, p1: TJActionRequest?, p2: String?) {}
override fun onRewardRequest(p0: TJPlacement?, p1: TJActionRequest?, p2: String?, p3: Int) { }
override fun onClick(p0: TJPlacement?) {
if (p0 != null) {
TapjoyLog.i(TAG, "onClick for direct play placement " + p0.getName())
}
}
}
directPlayPlacement?.videoListener = object: TJPlacementVideoListener {
override fun onVideoStart(p0: TJPlacement?) {}
override fun onVideoError(p0: TJPlacement?, p1: String?) {
activity.toast(getString(R.string.adds_content_empty))
}
override fun onVideoComplete(p0: TJPlacement?) {
getReward(4)
}
}
//load ad
if (directPlayPlacement != null) {
directPlayPlacement!!.requestContent();
} else {
Log.d(TAG, "Tapjoy SDK must finish connecting before requesting content.")
}
}
}
Tapjoy.connect(activity, API_KEY, connectFlags, callbackTJ);
Tapjoy.setDebugEnabled(true);
}
这是 showTapjoyRewardedVideo() 函数:
private fun showTapJoyRewardedVideo() {
if (directPlayPlacement == null) {
Log.d(TAG, "Tapjoy: Direct Play placement is null. No direct play video to show")
}
if (directPlayPlacement?.isContentAvailable!!) {
if (directPlayPlacement!!.isContentReady) {
directPlayPlacement!!.showContent();
} else {
Log.d(TAG, "Tapjoy: Video not ready to show")
}
} else {
Log.d(TAG, "Tapjoy: No video to show")
}
}
LogCat: http: //prntscr.com/udhl8e
请注意,我已将我的设备添加为测试设备,但它们仍然没有出现,而且我要求来自不同国家的人打开奖励视频,因为我认为他们没有适用于我的国家的视频,没有不工作。
编辑:我忘了提到使用上面的代码,另一个名为 AppLaunch 的默认放置显示为模式,这意味着集成有效,但它不适用于奖励视频。
任何帮助将不胜感激!