Found 2041 Articles for Mobile Development

How to show a dialog to confirm that the user wishes to exit an Android Activity?

Azhar
Updated on 22-Nov-2019 12:31:33

2K+ Views

This example demonstrates how do I show a dialog to confirm that the user wishes to exit an Android Activity.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 androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; 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);    }    @Override ... Read More

How to detect swipe direction between left/right and up/down in Android?

Azhar
Updated on 22-Nov-2019 12:28:01

2K+ Views

This example demonstrates how do I detect swipe direction between left/right and up/down 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 androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import android.view.GestureDetector; import android.view.MotionEvent; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    OnSwipeTouchListener onSwipeTouchListener;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);     ... Read More

How to set a Timeout for an AsyncTask in Android?

Azhar
Updated on 22-Nov-2019 12:21:21

908 Views

This example demonstrates how do I set a Timeout for an AsyncTask 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 androidx.appcompat.app.AppCompatActivity; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    Button button;    EditText editTextTime;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState); ... Read More

How do detect Android user agent type in general?

Azhar
Updated on 22-Nov-2019 12:16:06

171 Views

This example demonstrates how do I detect an Android user agent type in general 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 androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.media.AudioManager; import android.os.Bundle; import android.widget.Toast; import java.util.Objects; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       AudioManager am = ... Read More

How to find the currently running applications programmatically in Android?

Azhar
Updated on 22-Nov-2019 12:11:46

893 Views

This example demonstrates how do I find the currently running applications 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 androidx.appcompat.app.AppCompatActivity; import android.app.ActivityManager; import android.content.Context; import android.os.Bundle; import android.widget.TextView; import java.util.List; import java.util.Objects; public class MainActivity extends AppCompatActivity {    TextView textView;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       ... Read More

How to change status bar color to match app Android?

Azhar
Updated on 22-Nov-2019 12:08:36

3K+ Views

This example demonstrates how do I change the status bar color to match app 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 androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; import android.os.Bundle; import android.view.Window; import android.view.WindowManager; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       Window window = MainActivity.this.getWindow();     ... Read More

How to detect device is Android phone or Android tablet?

Azhar
Updated on 22-Nov-2019 08:48:25

2K+ Views

This example demonstrates how do I detect the device is an Android phone or Android tablet.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 androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.os.Bundle; import android.telephony.TelephonyManager; import android.widget.Toast; import java.util.Objects; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       TelephonyManager manager = ... Read More

How to detect touch and its position on Google map in Android?

Azhar
Updated on 22-Nov-2019 08:11:36

632 Views

This example demonstrates how do I detect touch and its position on Google map in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Google Maps 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 androidx.fragment.app.FragmentActivity; import android.os.Bundle; import android.widget.Toast; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleMap.OnCameraMoveStartedListener,    GoogleMap.OnCameraMoveListener,    GoogleMap.OnCameraMoveCanceledListener,    GoogleMap.OnCameraIdleListener {        private GoogleMap mMap;    @Override ... Read More

How to set selected item of Spinner by value instead of by position on Android?

Azhar
Updated on 22-Nov-2019 08:04:30

4K+ Views

This example demonstrates how do I set the selected item of Spinner by value instead of by position on 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 androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Spinner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class MainActivity extends AppCompatActivity {    Spinner spinner;    String[] FootBallPlayers = new String[]{"Lionel Messi", ... Read More

How to determine Android device screen size category (small, normal, large, xlarge) programatically?

Azhar
Updated on 22-Nov-2019 07:58:57

556 Views

This example demonstrates how do I determine the Android device screen size category (small, normal, large, xlarge) 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 androidx.appcompat.app.AppCompatActivity; import android.content.res.Configuration; import android.os.Bundle; import android.util.DisplayMetrics; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main); ... Read More

Advertisements