In This example creating a simple repeating alarm system with the use of AlarmManager. Alarm will start after each 2 mins.
1. Using AlarmManager class to repeating and called a PendingIntent after each 2 min.
2. Call a media file on PendingIntent and start media file.
3. So after each 2 min AlarmManager will call PendingIntent a media file start.
In this example broadcasting screen wake / sleep event with a service.
Some times we have requirement to make less battery consumption then you can stop your services when phone is going to sleep mode and again start your services when phone is going to wake.
1. Create a service inside main activity to get screen wake / sleep broadcast events.
2. Create a broadcast receiver inside service to get screen wake / sleep events.
3. Send screen wake/sleep value from broadcast receiver to Service.
In this example scaning for number of available wifi connections , Creating a broadcast receiver which will called when number of wifi connections changed.
In this example creating a date picker to pick day , month , year of date.
In this example creating a custom dialog with image,text and button.
Dialog is like a popup window to show some options to users(options like accept/decline).
Using class android.app.Dialog to create dialog.
Using dialog.xml file to create custom dialog layout.
In this example creating a custom toast alert with one image and text.
Toast alert is a notification message that display for certain amount of time, and automtaically fades out after set time.
Use it to show alert message to user.
Use it for debugging your application.
android.widget.Toast class used to create toast alert message.
In this example creating time picker with 12 hours format with AM/PM values.
android.widget.TimePicker class to create time picker.
Use OnTimeChangedListener to get time picker event.
In this example creating time picker. time picker is used for selecting the time of day, in either 24 hour or AM/PM mode. The hour, each minute digit, and AM/PM (if applicable) can be conrolled by vertical spinners.
In this Example creating custom spinner with one image and two texts.
After spinner item selection showing selected item text on screen.
1. Create Model (SpinnerModel.java) to store data for each spinner row.
2. Create a ArrayList to store Model (SpinnerModel.java) objects.
3. Store data in Models and Store Model objects in Arraylist.
4. Pass Model object Arraylist to custom adapter.
5. Custom Adapter use Arraylist data (Model Objects) and create rows for Spinner.
6. Create listener for Spinner and show spinner item selected values on activity.
In this example uploading an image from sdcard to web server.
Steps :
1. place an image on sdcard.
2. place sdcard image path and image name in UploadToServer.java. ( see below )
3. create a php script (UploadToServer.php) at server. ( see below )
4. place php script path in UploadToServer.java. ( see below )
5. create folder name uploads on server where you have placed php script.
6. give permission 777 (read/write/execute) to uploads folder.
In this example creating a simple spinner (Dropdown list).
Creating listener for spinner item selection and showing selected option in alert.
Creating listener for button to show selected spinner item.
In this example creating a checkbox and using selectors and shapes to give custom look.
Using selectors to call checkbox checked state xml and unchecked state xml.
Using xml file to create shape with the use of gradient,stroke tags to give custom look for checkbox checked and unchecked state.
Founder of Android Example.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook.
Email: info@androidexample.com
Sign up our newsletter and get exclusive deals you will not find anywhere else straight to your inbox!
© 2024 AndroidExample All Rights Reserved.
This website uses cookies to ensure you get the best experience on our website. For more information Learn about cookies