Read and write files in app private storage

This post shows how to create a text file in private app storage and access all files in private app storage. In AndroidManifest.xml add a FileProvider. In xml folder in res/ and in res/xml/ add a file provider_paths.xml. Create your layout in activity_main.xml. In MainActivity.java use following codes. Create private_storage.xml in res/layout/ folder. Create recycler_item.xml … Read more

Android pick image and display in ImageView

This post describes how to start a Service and stop a Service on Button click. Create your layout in activity_main.xml. Add a TextView, a Button and an ImageView. In MainActivity.java add following code. Now run the app. If you want to use the Activity Result APIs (ActivityResultContract and ActivityResultCallback to return an ActivityResultLauncher), use following … Read more

Toggle fullscreen immersive mode example

This post describes how to toggle between normal mode and fullscreen immersive mode using immersive mode fragment. Create your layout in activity_main.xml. In MainActivity.java use following code. In res/ folder create a menu/ folder, and in res/menu/ folder create main.xml. In res/menu/main.xml add a menu item Toggle Immersive Mode. Create a java class file ImmersiveModeFragment.java … Read more

Pick date and time and save in SharedPreferences

This post describes how to set date and time together using DatePickerDialog and TimePickerDialog and save the date and time set in SharedPreferences. In activity_main.xml add a Button and a TextView. In MainActivity.java use following code. Now run the app. It will show DatePickerDialog when button is clicked. It will show TimePickerDialog when date is … Read more

Show Fragments in ViewPager attached to TabLayout

This post describes how to create a ViewPager which displays Fragments according to the Tabs selected in TabLayout. In activity_main.xml add a TabLayout and a ViewPager. 2. Create fragment1.xml. 3. Create FirstFragment.java. 4. Create fragment2.xml. 5. Create SecondFragment.java. 6. Create fragment3.xml. 7. Create ThirdFragment.java. 8. In MainActivity.java, set up the ViewPager with TabLayout and display … Read more

Custom Toast Message

This tutorial shows how to create a custom Toast message from a CustomView in xml, and display it in android app. Here the custom Toast will display an icon with white text (displaying current time) in a rectangle with red background and 10dp elevation. Follow the steps given below. Step 1: Create a new project with … Read more

Android Camera Example

This tutorial shows how to launch camera in android, capture an image, and display the captured image in an ImageView. It is easy, just follow the steps given below. Step 1: Create a new project with name CameraExample and package name com.myexample.camera. Select File/New/New Project. Fill the forms and click “Finish” button. Step 2: Open res/layout/xml (or) … Read more

Create Stopwatch Android App

To create a stopwatch app for android, we can use android Chronometer. Here we will create a simple Stopwatch with an START/STOP button and a PAUSE/RESUME button. Step 1: Create a new project with name StopWatch and package name com.myexample.stopwatch. Select File/New/New Project. Fill the forms and click “Finish” button. Step 2: Open res/layout/xml (or) main.xml and add … Read more

Create BMI Calculator App

Here we will create a simple app which calculates the Body Mass Index of an individual using his weight and height. Step 1: Create a new project with name ‘BMI Calculator’ and package name com.myexample.appcompat.bmi. Fill the forms and click “Finish” button. Step 2: In app level build.gradle add following dependencies: Step 3: Open res -> layout -> xml (or) … Read more