「Android/広告組込/google/admob/リワード新」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==リワードサンプル旧api== 公式:https://developers.google.com/admob/android/rewarded-ads?hl=ja 以下記述のunitidはサンプルのid <pre> import com.go...」) |
(相違点なし)
|
2020年1月24日 (金) 15:19時点における版
リワードサンプル旧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(mListener); } OnClickListener mListener = new View.OnClickListener() { @Override public void onClick(View v) { if (rewardedAd.isLoaded()) { Activity activityContext = ...; RewardedAdCallback adCallback = 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 } }; // 広告表示 rewardedAd.show(activityContext, adCallback); } else { Log.d("TAG", "The rewarded ad wasn't loaded yet."); } } } }