Android/広告組込/google/admob/リワード新
提供: 初心者エンジニアの簡易メモ
リワードサンプル旧api
公式:https://developers.google.com/admob/android/rewarded-ads?hl=ja
以下記述のunitidはサンプルのid
import com.google.android.gms.ads.rewarded.RewardedAd; public class MainActivity extends Activity { private RewardedAd rewardedAd; @Override protected void onCreate(Bundle savedInstanceState) { rewardedAd = new RewardedAd(this, "ca-app-pub-3940256099942544/5224354917"); RewardedAdLoadCallback adLoadCallback = new RewardedAdLoadCallback() { @Override public void onRewardedAdLoaded() { // Ad successfully loaded. } @Override public void onRewardedAdFailedToLoad(int errorCode) { // Ad failed to load. } }; rewardedAd.loadAd(new AdRequest.Builder().build(), adLoadCallback); myButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); } RewardedAdCallback mAdCallback = new RewardedAdCallback() { public void onRewardedAdOpened() { // Ad opened. } public void onRewardedAdClosed() { // Ad closed. } public void onUserEarnedReward(@NonNull RewardItem reward) { // User earned reward. } public void onRewardedAdFailedToShow(int errorCode) { // Ad failed to display } }; void load() { if (rewardedAd.isLoaded()) { // 広告表示 rewardedAd.show(getContext(), mAdCallback); } else { Log.d("TAG", "The rewarded ad wasn't loaded yet."); } } }