My code is here
I have test it on my device I also integrate this app on firebase.
but it never go to onRewarded it always call onRewardedFaild why sir?
can anyone help me.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this,APP_ID);
mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
mRewardedVideoAd.setRewardedVideoAdListener(this);
loadRewardedVideoAd();
// Create the "retry" button, which tries to show an interstitial between game plays.
mRetryButton = ((Button) findViewById(R.id.retry_button));
mRetryButton.setVisibility(View.INVISIBLE);
mRetryButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startGame();
}
});
// Create the "show" button, which shows a rewarded video if one is loaded.
mShowVideoButton = ((Button) findViewById(R.id.watch_video));
mShowVideoButton.setVisibility(View.INVISIBLE);
mShowVideoButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showRewardedVideo();
}
});
// Display current coin count to user.
mCoinCountText = ((TextView) findViewById(R.id.coin_count_text));
mCoinCount = 0;
mCoinCountText.setText("Coins: " + mCoinCount);
startGame();
}
#Override
public void onPause() {
super.onPause();
pauseGame();
mRewardedVideoAd.pause(this);
}
#Override
public void onResume() {
super.onResume();
if (!mGameOver && mGamePaused) {
resumeGame();
}
mRewardedVideoAd.resume(this);
}
private void pauseGame() {
mCountDownTimer.cancel();
mGamePaused = true;
}
private void resumeGame() {
createTimer(mTimeRemaining);
mGamePaused = false;
}
private void loadRewardedVideoAd() {
if (!mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.loadAd(AD_UNIT_ID, new AdRequest.Builder().build());
/* AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("40C4DDA8F53FFA9BA5B61261E0CA28AB") // Test devices don't work work with rewarded video ads.
.build();
mRewardedVideoAd.loadAd(AD_UNIT_ID, adRequest);*/
}
}
private void addCoins(int coins) {
mCoinCount = mCoinCount + coins;
mCoinCountText.setText("Coins: " + mCoinCount);
}
private void startGame() {
// Hide the retry button, load the ad, and start the timer.
mRetryButton.setVisibility(View.INVISIBLE);
mShowVideoButton.setVisibility(View.VISIBLE);
loadRewardedVideoAd();
createTimer(COUNTER_TIME);
mGamePaused = false;
mGameOver = false;
}
// Create the game timer, which counts down to the end of the level
// and shows the "retry" button.
private void createTimer(long time) {
final TextView textView = ((TextView) findViewById(R.id.timer));
if (mCountDownTimer != null) {
mCountDownTimer.cancel();
}
mCountDownTimer = new CountDownTimer(time * 1000, 50) {
#Override
public void onTick(long millisUnitFinished) {
mTimeRemaining = ((millisUnitFinished / 1000) + 1);
textView.setText("seconds remaining: " + mTimeRemaining);
}
#Override
public void onFinish() {
if (mRewardedVideoAd.isLoaded()) {
mShowVideoButton.setVisibility(View.VISIBLE);
}
textView.setText("You Lose!");
addCoins(GAME_OVER_REWARD);
mRetryButton.setVisibility(View.VISIBLE);
mGameOver = true;
}
};
mCountDownTimer.start();
}
private void showRewardedVideo() {
mShowVideoButton.setVisibility(View.INVISIBLE);
if (mRewardedVideoAd.isLoaded()) {
mRewardedVideoAd.show();
}
}
#Override
public void onRewardedVideoAdLeftApplication() {
Toast.makeText(this, "onRewardedVideoAdLeftApplication", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdClosed() {
Toast.makeText(this, "onRewardedVideoAdClosed", Toast.LENGTH_SHORT).show();
// Preload the next video ad.
loadRewardedVideoAd();
}
#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 onRewarded(RewardItem reward) {
Toast.makeText(this,
String.format(" onRewarded! currency: %s amount: %d", reward.getType(),
reward.getAmount()),
Toast.LENGTH_SHORT).show();
addCoins(reward.getAmount());
}
#Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "onRewardedVideoStarted", Toast.LENGTH_SHORT).show();
}
I am using my Ad_Unit_ID Live not tested Device ID
Related
I am new in android studio, I have this code for showing interstitial.
Now I want to add timer before showing interstitial ad according admob policy.
but no idea how to add this. can someone help me out to do this?
private void goMainScreen(int position) {
if (mInterstitialAd != null) {
mInterstitialAd.show(this);
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdClicked() {
super.onAdClicked();
}
#Override
public void onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent();
startActivity(new Intent(MainActivity.this, SignsActivity.class));
Pref.getInstance(MainActivity.this).setIndex(position);
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
super.onAdFailedToShowFullScreenContent(adError);
startActivity(new Intent(MainActivity.this, SignsActivity.class));
Pref.getInstance(MainActivity.this).setIndex(position);
}
#Override
public void onAdImpression() {
super.onAdImpression();
}
#Override
public void onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent();
}
});
} else {
startActivity(new Intent(MainActivity.this, SignsActivity.class).putExtra("index", position));
Pref.getInstance(MainActivity.this).setIndex(position);
}
adPosition = adPosition + 1;
}
I have created an app with the rewarded video ad. When I click the button, the ad is not being loaded. I have tried testing the ad unit id and also my admob id, but neither work. Whenever I click the button, it shows " No fill from ad server. Failed to load ad: 3 "
I don't known what to do.
MobileAds.initialize(getApplicationContext(),"ca-app-pub-4786107620829013~6803627405");
mad = MobileAds.getRewardedVideoAdInstance(this);
mad.setRewardedVideoAdListener(this);
mad.loadAd("ca-app-pub-xxxxxxxxxxx", new AdRequest.Builder().build());
public void Clicked(View view) {
if (mad.isLoaded())
{
mad.show();
}
}
#Override
public void onRewardedVideoAdLoaded() {
Toast.makeText(this, "Video loaded", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdOpened() {
Toast.makeText(this, "Video Opened", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoStarted() {
Toast.makeText(this, "Video Started", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoAdClosed() {
}
#Override
public void onRewarded(RewardItem rewardItem) {
}
#Override
public void onRewardedVideoAdLeftApplication() {
}
#Override
public void onRewardedVideoAdFailedToLoad(int i) {
Toast.makeText(this, "Fail", Toast.LENGTH_SHORT).show();
}
#Override
public void onRewardedVideoCompleted() {
Toast.makeText(this, "Complete Video", Toast.LENGTH_SHORT).show();
}
Every time when i run the code its call onRewardedVideoAdFailedToLoad(int i) function. I am using codelabs example.
Sorry for bad English and thanks for helping me.
here is my code. I used many tutorial .
Is there anything I did it in the wrong way?
Or I just missed some steps?
public class Rewardedvideo extends AppCompatActivity implements
RewardedVideoAdListener {
RewardedVideoAd mAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rewardedvideo);
MobileAds.initialize(getApplicationContext(), "ca-app-pub-
3940256099942544~3347511713");
mAd=MobileAds.getRewardedVideoAdInstance(Rewardedvideo.this);
mAd.setRewardedVideoAdListener(this);
loadrewardedvideoAd();
}
public void loadrewardedvideoAd(){
if(!mAd.isLoaded()){
mAd.loadAd("ca-app-pub-3940256099942544/5224354917",new
AdRequest.Builder().build());
}
}
public void startvideo(){
if(mAd.isLoaded()){
mAd.show();
}
else {
mAd.loadAd("ca-app-pub-3940256099942544/5224354917",new
AdRequest.Builder().build());
mAd.show();
}
}
#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();
startvideo();
}
#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 onResume() {
mAd.resume(this);
super.onResume();
}
#Override
public void onPause() {
mAd.pause(this);
super.onPause();
}
#Override
public void onDestroy() {
mAd.destroy(this);
super.onDestroy();
}
}
here is my code. I used many tutorial .
Is there anything I did it in the wrong way?
Or I just missed some steps?
I think this is not get video source.
try again after few time
I use this library For downloading files , It is awesome library , but i need sofar downloaded byte (its parameter of progress) in the oncreate for updating the progress bar in onCreate.
This is My code :
public class MainActivity extends AppCompatActivity {
private Button btnDownload;
private ProgressBar prgDownload;
private int downloadId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
////////////////////////////////////////////////////////////
//================== Init Views ===========
////////////////////////////////////////////////////////////
btnDownload = (Button) findViewById(R.id.btnDownload);
prgDownload = (ProgressBar) findViewById(R.id.prgDownload);
final String savePath = FileDownloadUtils.getDefaultSaveRootPath() + File.separator + "angry.apk";
final String url = "http://dl2.soft98.ir/mobile/Angry.Birds.Rio.2.6.1_Soft98.iR.apk";
////////////////////////////////////////////////////////////
//================== Init Download Manager ===========
////////////////////////////////////////////////////////////
btnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
downloadId = createDownloadTask(url,savePath).start();
}
});
}
////////////////////////////////////////////////////////////
//================== Start Download Manager ===========
////////////////////////////////////////////////////////////
private BaseDownloadTask createDownloadTask(final String url , final String savePath){
return FileDownloader.getImpl().create(url)
.setPath(savePath)
.setListener(new FileDownloadListener() {
#Override
protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
Toast.makeText(MainActivity.this, "We are in pending ... ", Toast.LENGTH_SHORT).show();
}
#Override
protected void started(BaseDownloadTask task) {
super.started(task);
}
#Override
=====> protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
prgDownload.setMax(totalBytes);
prgDownload.setProgress(soFarBytes);
btnDownload.setText("Stop");
btnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FileDownloader.getImpl().pause(downloadId);
}
});
}
#Override
protected void completed(BaseDownloadTask task) {
Toast.makeText(MainActivity.this, "Download is Completed !!!", Toast.LENGTH_SHORT).show();
btnDownload.setText("Open");
}
#Override
protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
btnDownload.setText("Resume");
btnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createDownloadTask(url, savePath).start();
Toast.makeText(MainActivity.this, "Resume", Toast.LENGTH_SHORT).show();
}
});
}
#Override
protected void error(BaseDownloadTask task, Throwable e) {
Toast.makeText(MainActivity.this, "We have Error !!!", Toast.LENGTH_SHORT).show();
}
#Override
protected void warn(BaseDownloadTask task) {
Toast.makeText(MainActivity.this, "We have warn !!!", Toast.LENGTH_SHORT).show();
}
});
}
#Override
protected void onDestroy() {
super.onDestroy();
FileDownloader.getImpl().pause(downloadId);
}
}
Getting Error of 551 & 550 in this,
Here is my code :
findViewById(R.id.verifybutton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!TextUtils.isEmpty(phoneNumbTv.getText().toString())) {
verify();
}
else {
Toast.makeText(getApplicationContext(), "Please enter your phone number to verify", 3500).show();
}
}
});
private void verify() {
timerLayout.setVisibility(View.VISIBLE);
countDownTimer = new CountDownTimer(60000, 1000) {
#Override
public void onTick(long millisUntilFinished) {
timertv.setText("" + millisUntilFinished / 1000);
}
#Override
public void onFinish() {
timerLayout.setVisibility(View.GONE);
}
};
countDownTimer.start();
Cognalys.verifyMobileNumber(MainActivity.this, "TOKEN", "ID", phoneNumbTv.getText().toString(), new VerificationListner() {
#Override
public void onVerificationStarted() {
// TODO Auto-generated method stub
}
#Override
public void onVerificationSuccess() {
countDownTimer.cancel();
timerLayout.setVisibility(View.GONE);
Log.d("", "SUCCESS");
showAlert("Your number has been verified\n\nThanks!!", true);
}
#Override
public void onVerificationFailed(ArrayList<String> errorList) {
countDownTimer.cancel();
timerLayout.setVisibility(View.GONE);
for (String error : errorList) {
Log.d("abx", "error............:" + error);
}
showAlert("Something went wrong.\n please try again", false);
}
});
}
private void showAlert(String message, boolean status) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
ImageView mImageView = (ImageView) dialog.findViewById(R.id.verify_im);
TextView messageTv = (TextView) dialog.findViewById(R.id.messagetv);
if (status) {
mImageView.setImageResource(R.drawable.blue_tick);
}
else {
mImageView.setImageResource(R.drawable.wrong);
}
messageTv.setText(message);
dialog.show();
}
NOTE: Registered app package name in Cognalys site..
Sorry, I cant add the "Cognalys tag" coz I'm not having 1500 reputation
Thanks