Found 1626 Articles for Android

How to use SharedPreferences on Android to store, read and edit values?

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

244 Views

This example demonstrates how do I use SharedPreferences on Android to store, read, and edit values.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.javapackage app.com.sample; import androidx.appcompat.app.AppCompatActivity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    EditText editTextName, editTextEmail;    public static final ... Read More

How to get the Android device's primary e-mail address?

Azhar
Updated on 22-Nov-2019 12:53:49

1K+ Views

This example demonstrates how do I get the android device's primary e-mail address.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.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import android.Manifest; import android.accounts.Account; import android.accounts.AccountManager; import android.app.Activity; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.util.Log; import android.util.Patterns; import android.widget.TextView; import android.widget.Toast; import java.util.regex.Pattern; public class MainActivity extends AppCompatActivity {    private Activity activity = ... Read More

How to send data from one Fragment to another Fragment in Android?

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

1K+ Views

This example demonstrates how do I set the Android permission on a folder/file on SD Card to be able to write to it.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 two fragment layouts and add the following code as given below −FragmentOne.javaimport android.content.Context; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; public class ... Read More

How to set the Android permission on a folder/file on SD Card to be able to write to it?

Azhar
Updated on 22-Nov-2019 12:38:02

952 Views

This example demonstrates how do I set the Android permission on a folder/file on SD Card to be able to write to it.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.os.Environment; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import java.io.BufferedReader; import java.io.DataInputStream; import ... Read More

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

3K+ 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

1K+ 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

256 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

1K+ 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

Advertisements