How to set interstitial ads to be show for each n seconds ?


ScheduledExecutorService schedul = Executors.newSingleThreadScheduledExecutor();
schedul.scheduleAtFixedRate(new Runnable() {
    @Override    public void run() {
        Log.i("start interstitial","interstitial has been start");
        runOnUiThread(new Runnable() {
            @Override            public void run() {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    Log.d("interstitial", "The interstitial wasn't loaded yet.");
                }

                loadInterstitialAd();
            }
        });

    }
},45,90,TimeUnit.SECONDS);
How to show dialog box that No internet connection in your android app

 @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (!isConnected()) {
            buildDialog(MainActivity.this).show();
        }
        else            {
                //what ever Your code is please put it here. 
            }

}

public boolean isConnected() {

    ConnectivityManager cm = (ConnectivityManager) this.getSystemService(this.CONNECTIVITY_SERVICE);
    NetworkInfo netinfo = cm.getActiveNetworkInfo();

    if (netinfo != null && netinfo.isConnected())
    {
        android.net.NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        android.net.NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

        if((mobile != null && mobile.isConnected()) || (wifi != null && wifi.isConnected()))
            return true;

         else return false;
    }
    else    return false;
}

public AlertDialog.Builder buildDialog(Context c) {

    AlertDialog.Builder builder = new AlertDialog.Builder(c);
    builder.setTitle("No Internet Connection");
    builder.setMessage("please trun on wifi or Mobile Data to access the app and again run the app. Press ok to Exit");

    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

        @Override        public void onClick(DialogInterface dialog, int which) {

            finish();
        }
    });

    return builder;
}
How to create a splash screen in android ?

In your first splash screen put the belwo code :

public class HomeActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT=3000;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        new Handler().postDelayed(new Runnable() {
            @Override            public void run() {
                Intent homeIntent = new Intent(HomeActivity.this,MainActivity.class);
                startActivity(homeIntent);
                finish();
            }
        },SPLASH_TIME_OUT);
    }
}


In the manifest file you have to make the below update : 


<application    android:allowBackup="true"    android:icon="@mipmap/ic_launcher"    android:label="@string/app_name"    android:roundIcon="@mipmap/ic_launcher"    android:supportsRtl="true"    android:theme="@style/AppTheme">

    <activity android:name=".HomeActivity" android:theme="@style/AppTheme.NoActionBar">

        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity    android:name=".MainActivity"    android:label="@string/app_name"    android:theme="@style/AppTheme.NoActionBar">
   
</activity>
How to set toolbar margin in android . how to set the text in the center using toolbar margin in your activity .

@Overrideprotected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.setTitleMargin(25, 15, 35, 15);
}
How to show the adview in log android .


AdView mAdView;
mAdView.setAdListener(new AdListener() {
    @Override    public void onAdLoaded() {
        Log.i("AdEvent: ", "onAdLoaded");
    }

    @Override    public void onAdOpened() {
        Log.i("AdEvent: ", "onAdOpened");
    }

    @Override    public void onAdClosed() {
        Log.i("AdEvent: ", "onAdClosed");
    }
 @Override    public void onAdFailedToLoad(int errorCode) {
        String message = String.format("onAdFailedToLoad ", getError(errorCode));
        Log.d("AdEvent", message);
    }
});

//Method to return the error code 
private String getErrorReason( int errorCode){
    switch (errorCode) {
        case AdRequest.ERROR_CODE_INTERNAL_ERROR:
            return "Internal error";
        case AdRequest.ERROR_CODE_INVALID_REQUEST:
            return "Invalid request";
        case AdRequest.ERROR_CODE_NETWORK_ERROR:
            return "Network Error";
        case AdRequest.ERROR_CODE_NO_FILL:
            return "No fill";
        default:
            return "Unknown error";
    }
}

After you run the app you will find the log as below 


How to set  interstitial  ads to be show for each n seconds ? ScheduledExecutorService schedul = Executors. newSingleThreadScheduledExec...