Don't show ads for Android API 8 or lower - java

Users with Android version 2.2 (API 8) don't seem to appreciate the advertisements that are in my Android application. I would like to disable ads for this Android version or lower. Is there some kind of if/else statement that can prevent the showAdsBanner() and showAdsInterstitial() functions from being loaded? This way the ads won't be loaded and shown to my users.
public class App extends DroidGap implements AdListener
{
private Handler mHandler = new Handler();
private AdView adView;
private InterstitialAd interstitial;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl(Config.getStartUrl());
showAdsBanner();
mHandler.postDelayed(new Runnable() {
public void run() {
showAdsInterstitial();
}
}, 2500);
}
}
I'm fairly new to Java and I can't seem to find a working solution. I would greatly appreciate any help. Thank you.

http://developer.android.com/reference/android/os/Build.VERSION.html#SDK_INT
if(Build.VERSION.SDK_INT > 8) {
showAdsBanner();
mHandler.postDelayed(new Runnable() {
public void run() {
showAdsInterstitial();
}
}, 2500);
}

Related

ScheduledThreadPoolExecutor does not work on Android. Why?

I am quite newbie with android development and I am trying to figure out why this does not work.
I run this idea on Eclipse and it works fine. But I cant make it work on any of my devices. The app shows the value at start but it dont refresh the value anymore.
public class MainActivity extends AppCompatActivity {
private TextView txtCrono;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.txtCrono = (TextView) findViewById(R.id.txtTiempo); //activity_main TextView
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
exec.scheduleAtFixedRate(new Runnable() {
#Override
public void run() {
txtCrono.setText(String.valueOf(System.currentTimeMillis()));
}
}, 0, 100, TimeUnit.MILLISECONDS);
}
}
Try to use runOnUIThread:
exec.scheduleAtFixedRate(new Runnable() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
txtCrono.setText(String.valueOf(System.currentTimeMillis()));
}
});
}
}, 0, 100, TimeUnit.MILLISECONDS);
Basically, you must access a View from the main UI thread. (I don't know why your code doesn't cause an error and the first runnable is successfully setText. Maybe only the first runnable is executed on the main UI thread.)

I can't get ads when I download my app from google play

I've added the Admob ad to our Android app. I'm getting Advertising from Android Studio. I receive ads when I manually install the APK file to the phone. However, I can't get ads when I upload the app to Google Play and download it from Google Play. I get error code 3 (ERROR_CODE_NO_FILL). I couldn't find the solution. PLEASE HELP !
android studio avd run img:
img1
when I manually install the APK file to the phone:
img2
When I download it from Google Play:
img3
#Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.AppTheme_NoActionBar);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadAdmobBanner();
AdmobBannerListener();
}
private void loadAdmobBanner() {
MobileAds.initialize(this, getString(R.string.admob_app_id));
mAdView_Banner = findViewById(R.id.adView_Banner_Main);
AdRequest adRequest = new AdRequest.Builder()
.build();
mAdView_Banner.loadAd(adRequest);
}
private void AdmobBannerListener(){
mAdView_Banner.setAdListener(new AdListener(){
#Override
public void onAdFailedToLoad(int i) {
super.onAdFailedToLoad(i);
Toast.makeText(MainActivity.this, String.valueOf(i), Toast.LENGTH_SHORT).show();
}
#Override
public void onAdClosed() {
super.onAdClosed();
}
#Override
public void onAdLeftApplication() {
super.onAdLeftApplication();
}
#Override
public void onAdOpened() {
super.onAdOpened();
}
#Override
public void onAdLoaded() {
super.onAdLoaded();
}
#Override
public void onAdClicked() {
super.onAdClicked();
}
#Override
public void onAdImpression() {
super.onAdImpression();
}
});
}
Please go to admobs account. > Go to app > ad units> check if add units are active and are associated with advertiser.
Usually adMob will take time to do this job.

Frosty glass background effect in android activity

I am trying to apply a frosty glass effect to the background image of an activity, but I don't know how to do this can anyone know or do this kind of application if yes then help me please.
Expected output:-
This is my code where I am using Blurry library but when the application run it does work as expected:-
public class SplashActivity extends AppCompatActivity {
long delay = 5000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_activity);
Blurry.with(getApplicationContext())
.radius(25)
.sampling(2)
.async()
.animate(500)
.capture(findViewById(R.id.content))
.into((ImageView) findViewById(R.id.content));
Timer runSplash = new Timer();
TimerTask showSplash = new TimerTask() {
#Override
public void run() {
finish();
startActivity(new Intent(SplashActivity.this,MainActivity.class));
}
};
runSplash.schedule(showSplash,delay);
}
}
May be this library is helpful to you.
https://android-arsenal.com/details/1/2192

Android Java: Update seekbar to show progress as audio file plays

This is my first Android/Java app. I am using the first answer here to try to initiate a repeating task, updating a seekbar ("timeSlider") to show progress as an audio file plays. Here is my code (eliminating a few irrelevant lines):
private int timeSliderInterval = 1000; // 1 second
private Handler timeSliderHandler;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
Intent intent = getIntent();
Runnable doUpdateTimeSlider = new Runnable() {
#Override
public void run() {
timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
updateTimeSlider();
}
};
void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}
void stopUpdateTimeSlider() {
timeSliderHandler.removeCallbacks(doUpdateTimeSlider);
}
final SeekBar timeSlider = (SeekBar) findViewById(R.id.timeSlider);
if (timeSlider != null) {
timeSliderHandler = new Handler();
startUpdateTimeSlider();
}
#Override
public void onDestroy() {
super.onDestroy();
stopUpdateTimeSlider();
}
The project does not display in the emulator. Tooltips show these errors:
In addition, the startUpdateTimeSlider and stopUpdateTimeSlider functions are showing this error in tooltips:
Also, in the Run window, I'm getting:
emulator: emulator window was out of view and was recentered
emulator: ERROR: _factory_client_recv: Unknown camera factory query
name in ' '
Any help will be greatly appreciated!
First issue is self explained, you need to add final modifier.
final Runnable doUpdateTimeSlider = ...
Second one - move startUpdateTimerSlider() method, now its inside onCreate() method
Looks like you missed }:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
Intent intent = getIntent();
Runnable doUpdateTimeSlider = new Runnable() {
#Override
public void run() {
timeSliderHandler.postDelayed(doUpdateTimeSlider, timeSliderInterval);
updateTimeSlider();
}
};
}//<--------HERE
void startUpdateTimeSlider() {
doUpdateTimeSlider.run();
}

Admob Interstitial Ads showing in the middle of the game

I just made game like ironpants, I'm trying to put interstitial ads when the game over.
but the interstitial ads always show in the middle of the game. I think it'll be annoying for users. and I'm afraid if Google will banned my admob account.
The interstitial ads only show after 5x game over.
I only have onescreen MainGameView.java
here's the code to show admob interstitial ads when the game was over
the methods to initialize the interstitial ads
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialiseAccelerometer();
// Create the interstitial
interstitial = new InterstitialAd(this, getResources().getString(R.string.InterstitialAd_unit_id));
}
public void openAd() {
runOnUiThread(new Runnable() {
public void run() {
// Create ad request
AdRequest adRequest = new AdRequest();
// Begin loading your interstitial
interstitial.loadAd(adRequest);
// Set Ad Listener to use the callbacks below
interstitial.setAdListener(new AdListener() {
#Override
public void onReceiveAd(Ad arg0) {
if (interstitial.isReady()) {
interstitial.show();
}
}
#Override
public void onPresentScreen(Ad arg0) {
}
#Override
public void onLeaveApplication(Ad arg0) {
}
#Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
}
#Override
public void onDismissScreen(Ad arg0) {
}
});
}
});
}
and I call openAd() method when the game was over
public synchronized void GameOver() {
if (adounter >= this.getResources().getInteger(R.integer.add_shows_every_X_gameovers)) {
openAd();
adounter = 0;
}
adounter++;
}
thank you very much and sorry for my bad English.
Your problem is that you are showing the interstitial d as soon as it is received (ie in AdListener#onReceiveAd). Don't do this. It provides a poor user experience and will ensure you get low ratings.
Instead show your add at a natural break in your app.
Instead show your add at a natural break in your app.
Exactly, to be more precise it would be good user experience if you do the following:
- request for the ad in onCreate
- in GameOver call:
if (interstitial.isReady()) {
interstitial.show();
}

Categories

Resources