facebook twitter hatena line email

「Android/広告組込/google/admob/リワード旧」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の4版が非表示)
行1: 行1:
==リワードサンプル古いapi==
+
==リワードサンプル旧api==
 
公式:https://developers.google.com/admob/android/rewarded-video?hl=ja
 
公式:https://developers.google.com/admob/android/rewarded-video?hl=ja
 +
 +
以下記述のunitidはサンプルのid
 +
 
<pre>
 
<pre>
 
import com.google.android.gms.ads.AdRequest;
 
import com.google.android.gms.ads.AdRequest;
行6: 行9:
 
import com.google.android.gms.ads.reward.RewardedVideoAd;
 
import com.google.android.gms.ads.reward.RewardedVideoAd;
  
public class MainActivity extends AppCompatActivity implements RewardedVideoAdListener {
+
public class MainActivity extends AppCompatActivity {
 
     private RewardedVideoAd mRewardedVideoAd;
 
     private RewardedVideoAd mRewardedVideoAd;
 
     @Override
 
     @Override
行14: 行17:
 
         MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
 
         MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
 
         mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
 
         mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
         mRewardedVideoAd.setRewardedVideoAdListener(this);
+
         mRewardedVideoAd.setRewardedVideoAdListener(mListener);
 
         loadRewardedVideoAd();
 
         loadRewardedVideoAd();
 
     }
 
     }
行38: 行41:
 
         super.onDestroy();
 
         super.onDestroy();
 
     }
 
     }
}
+
    // イベント
</pre>
+
    private RewardedVideoAdListener mListener = new RewardedVideoAdListener() {
 +
        @Override
 +
        public void onRewarded(RewardItem reward) {
 +
            Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
 +
                    reward.getAmount(), Toast.LENGTH_SHORT).show();
 +
            // Reward the user.
 +
        }
  
イベント
+
        @Override
<pre>
+
        public void onRewardedVideoAdLeftApplication() {
@Override
+
            Toast.makeText(this, "onRewardedVideoAdLeftApplication",
public void onRewarded(RewardItem reward) {
+
                    Toast.LENGTH_SHORT).show();
    Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
+
        }
            reward.getAmount(), Toast.LENGTH_SHORT).show();
+
    // Reward the user.
+
}
+
  
@Override
+
        @Override
public void onRewardedVideoAdLeftApplication() {
+
        public void onRewardedVideoAdClosed() {
    Toast.makeText(this, "onRewardedVideoAdLeftApplication",
+
            Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
            Toast.LENGTH_SHORT).show();
+
        }
}
+
  
@Override
+
        @Override
public void onRewardedVideoAdClosed() {
+
        public void onRewardedVideoAdFailedToLoad(int errorCode) {
    Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
+
            Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
}
+
        }
  
@Override
+
        @Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {
+
        public void onRewardedVideoAdLoaded() {
    Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
+
            Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
}
+
        }
  
@Override
+
        @Override
public void onRewardedVideoAdLoaded() {
+
        public void onRewardedVideoAdOpened() {
    Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
+
            Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
}
+
        }
  
@Override
+
        @Override
public void onRewardedVideoAdOpened() {
+
        public void onRewardedVideoStarted() {
    Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
+
            Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
+
        }
  
@Override
+
        @Override
public void onRewardedVideoStarted() {
+
        public void onRewardedVideoCompleted() {
    Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
+
            Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
}
+
        }
 
+
     }
@Override
+
public void onRewardedVideoCompleted() {
+
     Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
+
 
}
 
}
 
</pre>
 
</pre>

2020年1月24日 (金) 15:15時点における最新版

リワードサンプル旧api

公式:https://developers.google.com/admob/android/rewarded-video?hl=ja

以下記述のunitidはサンプルのid

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardedVideoAd;

public class MainActivity extends AppCompatActivity {
    private RewardedVideoAd mRewardedVideoAd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
        mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
        mRewardedVideoAd.setRewardedVideoAdListener(mListener);
        loadRewardedVideoAd();
    }
    private void loadRewardedVideoAd() {
        mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
                new AdRequest.Builder().build());
    }
    @Override
    public void onResume() {
        mRewardedVideoAd.resume(this);
        super.onResume();
    }

    @Override
    public void onPause() {
        mRewardedVideoAd.pause(this);
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mRewardedVideoAd.destroy(this);
        super.onDestroy();
    }
    // イベント
    private RewardedVideoAdListener mListener = new RewardedVideoAdListener() {
        @Override
        public void onRewarded(RewardItem reward) {
            Toast.makeText(this, "onRewarded! currency: " + reward.getType() + "  amount: " +
                    reward.getAmount(), Toast.LENGTH_SHORT).show();
            // Reward the user.
        }

        @Override
        public void onRewardedVideoAdLeftApplication() {
            Toast.makeText(this, "onRewardedVideoAdLeftApplication",
                    Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoAdClosed() {
            Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoAdFailedToLoad(int errorCode) {
            Toast.makeText(this, "onRewardedVideoAdFailedToLoad", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoAdLoaded() {
            Toast.makeText(this, "onRewardedVideoAdLoaded", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoAdOpened() {
            Toast.makeText(this, "onRewardedVideoAdOpened", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoStarted() {
            Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRewardedVideoCompleted() {
            Toast.makeText(this, "onRewardedVideoCompleted", Toast.LENGTH_SHORT).show();
        }
    }
}

広告表示

if (mRewardedVideoAd.isLoaded()) {
    mRewardedVideoAd.show();
}