我解决了这个问题大约 3 天。我正在实施 Appodeal 的奖励广告。当我第一次启动我的应用程序时它工作正常。调用了 Appodeal onRewardedVideoLoaded 函数,它工作正常。但是在关闭应用程序并再次运行后。它总是调用 onRewardedVideoFailedToLoad 函数并且不加载广告。下面是我的代码。
请检查此代码。谢谢
/** Set up button to show an ad when clicked */
show_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//ad.show();
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
Appodeal.show(getActivity(), Appodeal.REWARDED_VIDEO);
}
}
});
//appodeal
Appodeal.setAutoCache(Appodeal.REWARDED_VIDEO, false);
Appodeal.initialize(getActivity(), appKey, Appodeal.REWARDED_VIDEO);
// Appodeal.setTesting(true);
Appodeal.setLogLevel(com.appodeal.ads.utils.Log.LogLevel.verbose);
Appodeal.cache(getActivity(), Appodeal.REWARDED_VIDEO);
if (Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)) {
progress.setVisibility(View.INVISIBLE);
System.out.println("Is loaded so enable");
show_button.setText("Earn Reward");
}
Appodeal.setRewardedVideoCallbacks(new RewardedVideoCallbacks() {
private Toast mToast;
@Override
public void onRewardedVideoLoaded() {
System.out.println("onRewardedVideoLoaded");
show_button.setEnabled(true);
progress.setVisibility(View.INVISIBLE);
show_button.setText("Earn Reward");
}
@Override
public void onRewardedVideoFailedToLoad() {
System.out.println("onRewardedVideoFailedToLoad");
progress.setVisibility(View.INVISIBLE);
}
@Override
public void onRewardedVideoShown() {
System.out.println("onRewardedVideoShown");
show_button.setEnabled(false);
show_button.setText("Not Avalible");
progress.setVisibility(View.VISIBLE);
}
@Override
public void onRewardedVideoFinished(int amount, String name) {
System.out.println(String.format("onRewardedVideoFinished. Reward: %d %s", amount, name));
SharedPref.putIntPref("rewards_count", SharedPref.getIntPref("rewards_count", getContext()) + amount, getContext());
// watcher.RemainingRewards(SharedPref.getIntPref("rewards_count", getContext()));
UpdateRewards();
}
@Override
public void onRewardedVideoClosed(boolean finished) {
System.out.println(String.format("onRewardedVideoClosed, finished: %s", finished));
}
void showToast(final String text) {
if (mToast == null) {
mToast = Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT);
}
mToast.setText(text);
mToast.setDuration(Toast.LENGTH_SHORT);
mToast.show();
}
});
return view;
}