我必须在当前项目的android studio中实现Admob奖励视频。我已经尝试了所有类似的方法。.Youtube教程,Admob官方教程和脚本,但对我来说没有任何用。请帮忙。 期待有示例android studio项目在其中实现并运行奖励视频。
谢谢
答案 0 :(得分:-1)
package easyload.android.el.com.easyloadpk;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.reward.RewardItem;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;
public class OurSurvey extends AppCompatActivity implements RewardedVideoAdListener{
private RewardedVideoAd rvd;
Button btn;
private AdView mAdView;
TextView txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_our_survey);
btn = (Button) findViewById(R.id.btnad);
mAdView = findViewById(R.id.adView);
txt = (TextView) findViewById(R.id.textView);
//...............................................................................
// AdRequest adRequest = new AdRequest.Builder().build();
// mAdView.loadAd(adRequest);
//...............................................................................
MobileAds.initialize(this,"ca-app-pub-3940256099942544~3347511713");
rvd = MobileAds.getRewardedVideoAdInstance(this);
rvd.setRewardedVideoAdListener(this);
//................................................................................
loadad();
// AdView adView = new AdView(this);
// adView.setAdSize(AdSize.BANNER);
// adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
//...............................................................................
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(rvd.isLoaded()){
rvd.show();
}
else{
txt.setText("cnt");
}
}
});
}
private void loadad(){
rvd.loadAd("ca-app-pub-3940256099942544/5224354917",new AdRequest.Builder().build());
}
@Override
public void onRewardedVideoAdLoaded() {
txt.setText("holalalala");
}
@Override
public void onRewardedVideoAdOpened() {
}
@Override
public void onRewardedVideoStarted() {
}
@Override
public void onRewardedVideoAdClosed() {
}
@Override
public void onRewarded(RewardItem rewardItem) {
}
@Override
public void onRewardedVideoAdLeftApplication() {
}
@Override
public void onRewardedVideoAdFailedToLoad(int i) {
}
@Override
public void onRewardedVideoCompleted() {
}
@Override
public void onResume() {
rvd.resume(this);
super.onResume();
}
@Override
public void onPause() {
rvd.pause(this);
super.onPause();
}
}