Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Saturday, September 12, 2015

Android Internet Connection checking

private boolean isNetworkConnected() 
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null) 
{
       //There are no active networks.       return false;
} 
else
{
        return true;
}
}


The above function will return true only if the device has internet connection otherwise false.

manifest file permissions,
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Tuesday, March 11, 2014

How to add space between each controls( buttons, text box )..

There is simple way to add space between controls( buttons, text boxes..etc..) in an linear layout. Add the following attribute in the controls,

<Button
android:layout_width="280dp"
android:layout_height="40dp"
android:layout_marginTop="15dp"
/>

This will allow 15dp space above the button. Likewise you can give space between each controls. You can use the following attributes too,

android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"