Check Internet Connection Availability on Android

Azhar
Updated on 02-Aug-2019 07:13:31

462 Views

This example demonstrates how do I check internet connection availability in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new projectStep 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.net.ConnectivityManager; import android.net.NetworkInfo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       if (haveNetwork()){          Toast.makeText(MainActivity.this, "Network connection ... Read More

Pass Object Between Activities in Android

Azhar
Updated on 02-Aug-2019 07:02:51

3K+ Views

This example demonstrates how do I pass an object from one Activity to another in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Create a java class and add the following code in Character.javaimport java.io.Serializable; public class Character implements Serializable {    String name, Proffession, Position;    String[] abilities;    public Character(String name, String proffession, String position, String[] abilities) {       this.name = name;     ... Read More

Enable or Disable GPS Programmatically in Android

Azhar
Updated on 02-Aug-2019 06:57:46

3K+ Views

This example demonstrates how do I get enable/disable GPS programmatically in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.content.Context; import android.content.Intent; import android.location.LocationManager; import android.provider.Settings; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    Button button;    Context context;    Intent intent1;    TextView textview;    LocationManager locationManager ;    boolean ... Read More

Get Current GPS Location Programmatically on Android

Azhar
Updated on 02-Aug-2019 06:50:51

7K+ Views

This example demonstrates how do I get current GPS location programmatically in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml         Step 3 − Add the following code to src/MainActivity.javaimport android.content.pm.PackageManager; import android.location.Location; import android.os.Bundle; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.tasks.OnSuccessListener; import static android.Manifest.permission.ACCESS_FINE_LOCATION; public class MainActivity extends AppCompatActivity {    private FusedLocationProviderClient client;    @Override    protected void onCreate(Bundle ... Read More

Get Screen Dimensions in Pixels in Android App

Azhar
Updated on 02-Aug-2019 06:43:06

245 Views

This example demonstrates how do I get screen dimensions in pixels in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                 Step 3 − Add the following code to src/MainActivity.javaimport android.content.Context; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.WindowManager; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView one, two;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       ... Read More

Use Custom Font in an Android Project

Azhar
Updated on 02-Aug-2019 06:37:24

196 Views

This example demonstrates how do I use custom font in Android project.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.graphics.Typeface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity {    TextView tv;    Typeface myFont;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       tv = (TextView) findViewById(R.id.textView);   ... Read More

Delete SMS from Inbox in Android Programmatically

Azhar
Updated on 02-Aug-2019 06:28:23

2K+ Views

This example demonstrates how do I delete an sms from inbox in Android programmatically.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javaimport android.content.Context; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    private Context mContext;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

Set Only Numeric Value for EditText in Android

Azhar
Updated on 02-Aug-2019 06:08:36

846 Views

This example demonstrates how do I set only numeric value for editText in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity {    Button button;    EditText editText;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main); ... Read More

Read Data from Keyboard in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:27:57

5K+ Views

The java.io package provides various classes to read write data from various sources and destinations.You can read data from user (keyboard) using various classes such as, Scanner, BufferedReader, InputStreamReader, Console etc.Using Scanner classFrom Java 1.5 Scanner class was introduced. This class accepts a File, InputStream, Path and, String objects, reads all the primitive data types and Strings (from the given source) token by token using regular expressions. By default, whitespace is considered as the delimiter (to break the data into tokens).To read data from keyboard you need to use standard input as source (System.in). For each datatype a nextXXX() is ... Read More

Set File Permissions in Java

Maruthi Krishna
Updated on 01-Aug-2019 14:22:20

8K+ Views

In general, whenever you create a file you can restrict/permit certain users from reading/writing/executing a file.In Java files (their abstract paths) are represented by the Files class of the java.io package. This class provides various methods to perform various operations on files such as read, write, delete, rename etc.In addition, this class also provides the following methods −setExecutble() − This method is sued to set the execute permissions to the file represented by the current (File) object.setWritable() − This method is used to set the write permissions to the file represented by the current (File) object.setReadable() − This method is ... Read More

Advertisements