All for Android, Android for Allhttps://www.ssaurel.com/blog
News and Tutorials about Android and Java WorldFri, 11 Aug 2017 07:41:51 +0000en-UShourly1https://wordpress.org/?v=4.8.1Evolution of the iPhone through the Ages and what to expect for the iPhone 8https://www.ssaurel.com/blog/evolution-of-the-iphone-through-the-ages-and-what-to-expect-for-the-iphone-8/
https://www.ssaurel.com/blog/evolution-of-the-iphone-through-the-ages-and-what-to-expect-for-the-iphone-8/#respondFri, 11 Aug 2017 06:00:34 +0000https://www.ssaurel.com/blog/?p=1896Just this once, we are going to talk about Apple iPhone on the SSaurel’s Blog. The iPhone 8 is expected to be launched during the 2017 Fall and we expect some major improvements from the iPhone 7. To better understand the evolution of the iPhone through the Ages, look at this awesome infographic :

This infographic lets you to see that the iPhone has changed in height and width to equal screen size of Android concurrents like the Samsung Galaxy S7 or S8 for example.

We can also see that the Giga Bytes of RAM has been increased to reach 2 GB for the iPhone 7. Note that the iPhone 7 needs less RAM memory like the Samsung Galaxy S8 for example. However, like iOS is specifically optimized for the iPhone, it is simpler for Apple to offer a performant device with this amount of RAM.

Finally, we can note that each new iPhone has introduced some special features. From the Retina screen with the iPhone 4 to the Lightning connector with the iPhone 5 to arrive to a bigger size screen since the iPhone 6.

So, for the iPhone 8 what to expect ? The following video will offer you to discover the Top 8 Features we can expect for the iPhone 8 :

Let us know your thoughts about iPhone’s evolution and the upcoming iPhone 8 in comments.

]]>https://www.ssaurel.com/blog/evolution-of-the-iphone-through-the-ages-and-what-to-expect-for-the-iphone-8/feed/0Detect device year class on Android with Facebook Device Year Classhttps://www.ssaurel.com/blog/detect-device-year-class-on-android-with-facebook-device-year-class/
https://www.ssaurel.com/blog/detect-device-year-class-on-android-with-facebook-device-year-class/#respondThu, 10 Aug 2017 06:00:42 +0000https://www.ssaurel.com/blog/?p=1885When you make Android applications, it is always useful to know the year class of the running device. Indeed, with that information, you can adapt the behavior of your application to the smartphone or tablet of your users. Obviously, the main goal being to offer them a better experience with your application.

For that, Facebook offers Device Year Class an Android open source library implementing a simple algorithm which maps a device’s RAM, CPU cores and clock speed to the year where those combination of specifications were considered high end.

It allows you to easily modify the behavior of your Android application according the capabilities of the phone’s hardware. The mapping used by the algorithm of Facebook Device Year Class is based on the following table :

In this tutorial, you are going to discover how it is simple to use Facebook Device Year Class Library in your Android applications to detect the probable year class of the running phone.

You can also enjoy directly this tutorial on YouTube in video :

Integration

First step is to integrate Facebook Device Year Class Library in your Android application project. For that, you have just to add the following dependency in your build.gradle file :

compile 'com.facebook.device.yearclass:yearclass:2.0.0'

Get the year class of the device

Once the library is installed, you can get the year class of the device simply with the following code :

int year = YearClass.get(getApplicationContext());

Adapt the behavior of your Android App

With this information, you can modify the behavior of your application with the following snippet of code :

]]>https://www.ssaurel.com/blog/detect-device-year-class-on-android-with-facebook-device-year-class/feed/0Parse and write JSON data in Java with Gsonhttps://www.ssaurel.com/blog/parse-and-write-json-data-in-java-with-gson/
https://www.ssaurel.com/blog/parse-and-write-json-data-in-java-with-gson/#respondMon, 07 Aug 2017 06:00:53 +0000http://www.ssaurel.com/blog/?p=1187Nowadays, JSON is the most widespread format to exchange data on the Web. REST Web Services use it. JSON is lighter than XML and lets to save bandwith when you consume this services. In Java, there is a great library named Gson that makes developers’ life easier. Created by Google, Gson is open source and available on GitHub here : https://github.com/google/gson . It can be used to convert Java Objects into JSON format. At the opposite, it can be used to convert JSON string to Java objects.

In that tutorial, you’re going to learn how to parse JSON data to Java Objects and then, how to write Java Objects to JSON format.

1. Get Gson

First step is to get GSON. It can be used as a Maven dependency or you can download the JAR directly if you prefer.

When you execute this code, you get a gen.json file with Java Objects converted to JSON format.

7. Conclusion

Gson is a simple and powerful Java serialization / deserialization library that can convert Java Objects into JSON and back. Associated with a tool like JsonSchema2Pojo, it becomes a pleasure to use JSON data in Java.

8. Extra

You can also enjoy this tutorial with the following Youtube videos :

]]>https://www.ssaurel.com/blog/parse-and-write-json-data-in-java-with-gson/feed/0The Ultimate Guide to Java 9https://www.ssaurel.com/blog/the-ultimate-guide-to-java-9/
https://www.ssaurel.com/blog/the-ultimate-guide-to-java-9/#commentsTue, 01 Aug 2017 06:00:37 +0000http://www.ssaurel.com/blog/?p=1394After some months of delays, Java 9 is coming ! Java 9 is attended for general availability On September, 2017. In that article, you’re going to discover the major new features of Java 9. Don’t hesitate to leave me some comments if I forgot some important things.

Main Features

Java Platform Module System – JSR 376

Process API Updates – JEP 102

HTTP 2 Client – JEP 110

JShell : The Java Shell – JEP 222

Multi-Resolution Images API – JEP 251

Stack-Walking API – JEP 259

Platform Logging API and Service – JEP 264

Reactive Streams – JEP 266

Platform-Specific Desktop Features – JEP 272

Deserialization Filter – JEP 290

XML Catalogs – JEP 268

Parser API for Nashorn – JEP 236

Language Changes – JEP 213

Extension to Existing APIs

Some Low Level APIs

Applet API deprecation – JEP 289

You can discover all the new features expected in Java 9 in video too :

Java Platform Module System – JSR 376

The Java Platform Module System (JPMS) is the biggest part of Java 9. Specific goals of the module system are :

Reliable configuration

Strong encapsulation

It will benefit application developers, library developers and implementors of the Java SE Platform. An awesome read to start with JPMS :

Motivation : The limitations of the current API often force developers to resort to native code.

The design of this API needs to accommodate possible deployment on smaller devices with different OS models. The new ProcessHandle class makes it more convenient to interact with processes and process trees. Get the PID of the current Process :

Goal is to provide an interactive tool to evaluate declarations, statements, expressions of the Java language with and API letting other applications to leverage this functionality. With Java 9, the JDK will have its own Read-Eval-Print-Loop (REPL) tool !
Evaluate and print expressions :

Motivation : Existing APIs require the VM to eagerly capture a snapshot of the entire stack and they return information representing the entire stack. It’s an heavy operation ! The Stack-Walking API wants to solve this problem.

Make a couple of calls and then walk the stack until we find the frame that belongs to a specific method :

New stream returning methods are added with LocalDate::datesUntil, Scanner::tokens, …

Many types of the DateTime API introduced in Java 8 can now transform themselves to epoch seconds, e.g. Chronology , LocalDate , and OffsetTime

etc …

Some Low Level APIs

Java 9 brings a number of very interesting APIs that operate much closer to the JVM. Amongst them :

Variable Handles aka VarHandles – JEP 193

Enhanced Method Handles – JEP 274

Dynamic Linking of Language-Defined Object Models – JEP 276

Spin-Wait Hints – JEP 285

Applet API deprecation – JEP 289

Deprecate the Applet API, which is rapidly becoming irrelevant as web-browser vendors remove support for Java browser plug-ins. Guide developers to alternative technologies such as Java Web Start or installable applications. Applet API is just marked as deprecated but not for removal. So, Applet API will still be in JDK 10 at least …

Excited about Java 9 ? Which feature is the most expected for you ? Tell us in comments !

]]>https://www.ssaurel.com/blog/the-ultimate-guide-to-java-9/feed/1Transform your Android device into a real Centimeter Ruler to Measurehttps://www.ssaurel.com/blog/transform-your-android-device-into-a-real-centimeter-ruler-to-measure/
https://www.ssaurel.com/blog/transform-your-android-device-into-a-real-centimeter-ruler-to-measure/#respondMon, 31 Jul 2017 06:00:31 +0000http://www.ssaurel.com/blog/?p=1821Sometimes, when you are working on some personal projects you need to measure some small things. Unfortunately, you have nothing on you to measure these small things.

So, how can you measure these small things ?

By chance, you have always your Android smartphone with you. With My Ruler to Measure offered by SSaurel’s Mobile Apps, you will transform your Android device into a real Ruler to have always a tool to measure with you.

My Ruler to Measure is available on the Google Play Store in both versions :

In the following video, you are going to discover how to download My Ruler to Measure for Android and how to use it to measure things around you.

My Ruler to Measure will become quickly a must have tool in your Android device.

Let us know your thoughts in comments.

]]>https://www.ssaurel.com/blog/transform-your-android-device-into-a-real-centimeter-ruler-to-measure/feed/0Bixby Voice : Full list of commands for the Galaxy S8 and S8+https://www.ssaurel.com/blog/bixby-voice-full-list-of-commands-for-the-galaxy-s8-and-s8/
https://www.ssaurel.com/blog/bixby-voice-full-list-of-commands-for-the-galaxy-s8-and-s8/#respondTue, 25 Jul 2017 06:00:25 +0000http://www.ssaurel.com/blog/?p=1817Samsung has just made available Bixby Voice for US English. In that article, you are going to discover the full list of commands supported by Bixby Voice for the Samsung Galaxy S8 and S8+.

The commands are grouped by categories :

Common Commands

Open Facebook

What time is it?

What’s the date today?

Turn the volume up/down

Restart off my phone

Flashlight on/off

Turn on Emergency mode

Play music

Stop the music

What song is this?

What’s the name of this song?

Remind me to buy milk tomorrow at 9 am

Show me my most recent reminder

Delete the shopping reminder

What’s the weather like?

How is the weather going to be tomorrow?

Will it rain today?

What’s the weather in Boston tomorrow?

What’s the UV index in Miami tomorrow?

Screen & Navigation

Take a screenshot

Go back

Show the Home screen

Scroll up/down

Swipe left/right

Scroll to the top/bottom

Zoom in/out

Turn on auto rotate

Set the phone to portrait mode

Turn off the screen

Notifications & System Tasks

Show me my most recent app in split screen view

Close Messages

Close all recent apps

Open Messages in split screen view

Show me my recent apps

Open this app as a pop-up

Minimize this app

Switch windows

Close Messages

Clear notifications from Messages

Show me all notifications

Open the quick panel

Close the notification panel

Expand the notification from Messages

Control the brightness on the notification panel

Read all notifications

Read the latest notification

Questions & Answers

How far is the sun from Earth?

What is the definition of doodle?

How do you spell restaurant?

Who was the 44th president of the USA?

Show me how to make cheesecake

When is Thanksgiving?

Who was the first man on the moon?

How long is a cheetah’s tail?

What is 10×5?

How many calories in a bagel?

When is sunrise in Paris?

What is a fathom?

How many feet in a mile?

Samsung Apps

There are also some commands specific to Samsung Galaxy Apps.

Open Gallery and …

Find pictures taken in New York

Show me the most recent picture

Share this picture

Delete this picture

Show me the travel album

Show me the most recent pictures as a slideshow

Auto adjust the picture

Rotate this picture to the right

Play the most recent video

Show me the list of albums

Add the most recent picture from Friends album to Favorites

Remove the auto adjust effects from the most recent picture

Delete the location info from the most recent picture

Delete the travel album

Copy pictures taken at Christmas to a new album

Show the details for the most recent picture

Open Contacts and …

Create a new contact as David with the number 123–4567

Search for David and call him on speaker phone

Search for David and call his home

Call this number on speaker phone

Call my office number

Call David

Text David

Show David’s contact info

Show profile updates for David

Video call David’s mobile phone

Show my friends group

Make my birthday shared

Change my status message to busy

Link David to Jane

Add David to favorites

Send a message to everyone in Friends

Merge all contacts with the same info

Turn on Google account sync

Open Phone app and …

Show Recents

Show missed calls

Accept

Decline the call and Send the text as I am in a meeting

Call 123–4567 on speaker phone

Block 1234–5678

Call with speed dial number 2

Open the keypad

Make a call to 123–4567

Call the most recent number

Delete the most recent number

Show recent searches

Block David

Video call the most recent number

Block the last number called

Call this number

Add David to speed dial 2

Turn on vibrate when call ends

Open Settings and …

Turn on WiFi in Settings

Search for nearby WiFi networks in Settings

Disconnect from WiFi in Settings

Turn on Bluetooth in Settings

Scan for Bluetooth devices in Settings

Go to dual audio in Settings

Show me my Data usage

Turn on Data saver

Turn on Airplane mode

Show me NFC settings

Set the ringtone volume to 50

Increase the system volume

Turn on Do not disturb

Don’t disturb me between 10 pm and 7 am

Set the display brightness to 50

Make the screen brighter

Turn on Blue light filter

Open Messages and …

Show me the most recent message

Block the most recent conversation

Turn off notifications for the conversation with David

Copy the most recent text

Show me pictures from the conversation with David

Mark all unread messages as read

Delete all conversations

Take a photo and send it to David

Show me settings

Open Camera and …

Take a picture

Record a video

Turn on the front camera

Turn on HDR

Turn on Flash

Show me pictures

Set the timer for rear camera to 10 seconds

Apply an effect

Turn on Save RAW and JPEG files for rear camera

Turn on video stabilization

Adjust the ISO of Pro mode to 200

Adjust the exposure value of Pro mode to 1

Turn on grid lines

Open Clock and …

Set an alarm for tomorrow at 6 am

Turn off the 6 am alarm

Show me the time in New York

Dismiss the alarm

Show the timer

Open the stopwatch

Add London to my world clock

Open the time zone converter in the world clock

Open Calculator and …

Calculate 5 + 10 x 4

Show the unit converter

Convert 25 inches to cm

Open Calendar and …

Create an event

Show me March 23rd

Show me the month of October

Delete my completed tasks

Mark grocery shopping as done

Delete all of my meetings for today

Show me the settings

Change the first day of the week to Sunday

Show week numbers

Turn on notifications

Lock the time zone

Change the time zone to New York

Don’t hesitate to try these voice commands supported by Bixby Voice and give me your feedback on your experience with Bixby Voice. If you discover more commands, don’t hesitate to share them in comments too.

To discover more Android and Samsung related content, don’t hesitate to visit the SSaurel’s Channel :

]]>https://www.ssaurel.com/blog/bixby-voice-full-list-of-commands-for-the-galaxy-s8-and-s8/feed/0Recreate the Countdown Math Game on Androidhttps://www.ssaurel.com/blog/recreate-the-countdown-math-game-on-android/
https://www.ssaurel.com/blog/recreate-the-countdown-math-game-on-android/#respondMon, 19 Jun 2017 06:00:58 +0000http://www.ssaurel.com/blog/?p=1799The Countdown Math Game, also known as Good Count Math Game, is a game made famous in England with the TV game show Countdown which started in the sixties and then exported in a lot of countries around the World.

The Countdown Math Game involves number puzzles in which you must make arithmetic operations to reach a random target number (between 100 and 999) from 6 other numbers chosen randomly (from 1 to 10, 25, 50, 75 and 100). In this tutorial, you are going to create your own implementation of a solver for the Countdown Math Game on Android.

Note that you can discover this tutorial in video on YouTube :

You can also test directly an extended version of the Countdown Math Game we are going to create in this tutorial just here on the Google Play Store :

Modelize the Countdown Math Game

Before starting to create the algorithm to solve the Countdown Math Game, we are going to modelize the game. Like said previously, you can use the four primary artihmetic operations to solve a count :

Addition

Subtraction

Division

Multiplication

Basically, each operation take two parameters and return a result. Besides, for each operation we have an associated symbol. So, we can create an Operation interface to modelize the behaviour of an operation in the Countdown Math Game :

Algorithm to solve the Countdown Math Game

Now, we can create an algorithm to solve the Countdown Math Game. We are going to create a brute force algorithm iterating on all the numbers to use and applying all the possible operation to reach the target number.

You can note that we are going to use a list to store all the operations leading to a solution of a count to find. The printSolution method will just have to iterate on the list in the reverse way to display the operations leading to the number to reach.

Create the User Interface

With our CountdownMathGame object implemented, we have to create the User Interface of our game on Android. The UI will be quite simple with mainly two EditText components letting the users respectively to enter the number to use separated by a space and the number to reach. The last view will be a Button which will be useful to start the resolution of the Countdown Math Game.

Write the code of the Main Activity

Now, we can write the Java code of the Main Activity of our Countdown Math Game for Android. We just need to get the references of the UI’s views and then to set an OnClickListener implementation on the Button. When the user will click on it, we will have to get the numbers to use and to parse it from String to Integer. Then, we will get the number to reach from the second EditText.

With these numbers, we could launch the resolution of the Countdown Math Game by calling the findSolution method. We will put the numbers to use and the number to reach in parameter of this method.

Here, you can note that if there is a solution, we show it to the user in an AlertDialog. It is the main difference with the CountdownMathGame class presented previously in which we print the solution on standard output.

Our Countdown Math Game Solver for Android works great ! You can discover the algorithm implemented in this tutorial in action just here on YouTube :

]]>https://www.ssaurel.com/blog/recreate-the-countdown-math-game-on-android/feed/0Create a Roll Dice Game on Android with Shake Effecthttps://www.ssaurel.com/blog/create-a-roll-dice-game-on-android-with-shake-effect/
https://www.ssaurel.com/blog/create-a-roll-dice-game-on-android-with-shake-effect/#respondMon, 12 Jun 2017 06:00:47 +0000http://www.ssaurel.com/blog/?p=1792A Roll Dice Game is a simple game in which you have to roll some dice and trying to make the highest score possible by adding the values of the two dice. In this tutorial, you are going to learn how to create a Roll Dice Game on Android. It’s a good way to discover how to manipulate simple view and how to get resources dynamically.

Besides, we are going to add a shake effect on the dice when the user will roll them to add a more realistic effect.

Note that you can enjoy this tutorial in video on YouTube via the SSaurel’s Channel :

Get Dice Images

Obviously, we need dice images for our Roll Dice Game. We are going to use these images with values from one to six :

Create the Shake Effect

To make our Roll Dice game more realistic, we are going to create a Shake Effect which will be applied on the dice when the user will roll them. For that, we create a shake.xml file under an anim folder on the resources directory of our Android project.

The Shake Animation is a set with a rotate animation and a translate animation for which we add a linear interpolator to make the effect smoother. It gives us the following XML code :

Write the Java Code

The last part of our tutorial consists to write the Java Code of our Main Activity. We start by getting the references of both Image Views and of the Button.

Then, we set an OnClickListener on the Button to write the code letting the dice to be rolled. First, we load the Shake Animation thanks to the static method loadAnimation of the AnimationUtils class from the standard SDK.

After that, we create an AnimationListener implementation. It will let us to change the value of the dice just after the end of the Shake Effect. So, we write our Java code in the onAnimationEnd method of the AnimationListener implementation.

In this method, we generate a new random value for the dice. It will be a value between 1 and 6. Then, we get the corresponding dice image dynamically by using the getIdentifier method of the Resources object got via the getResources method call. Last step is to set the image loaded on the correct imageView instance according the value of the animation just ended.

In the onClick method, we continue by setting this AnimationListener implementation on the both animatons loaded previously. Finally, we start the animation for each dice image by calling the startAnimation method with the correct animation in parameter.

]]>https://www.ssaurel.com/blog/create-a-roll-dice-game-on-android-with-shake-effect/feed/0Learn to create a Paint Application for Androidhttps://www.ssaurel.com/blog/learn-to-create-a-paint-application-for-android/
https://www.ssaurel.com/blog/learn-to-create-a-paint-application-for-android/#respondWed, 07 Jun 2017 06:00:54 +0000http://www.ssaurel.com/blog/?p=1779Paint applications are become famous thanks to Microsoft Paint, well known as simply Paint or Paintbrush. It was a simple computer graphics application included with all versions of Microsoft Windows. In this tutorial, you are going to discover how to create a Paint Application for Android which will let users to draw on the screen with their fingers.

Our Paint Application for Android will offer the following features to users :

Draw paths with fingers on the screen

Normal mode

Emboss mode

Blur mode

Clear option to remove all paths on the screen

Note that you can discover this tutorial in video directly on YouTube :

Even better, you can enjoy the demo of this Paint Application directly on your Android smartphones and tablets by downloading Tiny Paint on the Google Play Store :

Create the Paint View

With the possibility to represent a path drawn with the finger of the user on the screen, we need now to define a custom view to draw these paths on the screen. For that, we are going to create a PaintView class.

Obviously, our PaintView class will extend the View object from the standard SDK. The PaintView class will have some constants like the size the stroke width for the path also known as brush size or still the color of the path drawn.

The PaintView will store several FingerPath objects inside an ArrayList field. Besides, the PaintView object has a field for the Canvas used to draw the paths represented on the screen to the user.

In the constructor of the PaintView, we initialize the Paint Object used to draw the paths on the Canvas. We need to define the style of the Paint Object as STROKE. Then, we set the stroke join and stroke cap to ROUND. Finally, we create an EmbossMaskFilter Object for the emboss mode and an BlurMaskFilter for the blur mode.

This gives us the following code for the PaintView at this stage of the tutorial :

Now, we add an init method on the PaintView class. This method will take a DisplayMetrics Object in parameter and will be responsible to define the height and width of the PaintView. Furthermore, we initialize the Canvas and its underlying Bitmap used to draw paths on the screen.

The PaintView will expose three methods to switch between the three modes of drawing : normal, emboss and blur. The clear method will let us to clear the PaintView by clearing the list of Finger Paths. To let the users to visualize the changes on the screen, we don’t forget to call the invalidate method to redraw the PaintView.

Then, we override the onDraw method of the View class. First we save the current state of the Canvas instance before to draw the background color of the PaintView. We iterate on the list of Finger Paths and we draw the Path Object contained in the current FingerPath Object on the Canvas.

To apply the specific effect defined by the user, like emboss or blur, we set the corresponding mask filter on the Paint Object used to draw the FingerPath if needed. Finally, we draw all these elements on the Canvas of the PaintView and we restore the current Canvas.

Manage the users’ touches on the screen

Now, we need to manager the users’ touches on the screen to save the paths drawn on the screen with their fingers. We override the onTouchEvent method and we define three methods to manage the three following actions :

ACTION_DOWN with a touchStart method

ACTION_MOVE with a touchMove method

ACTION_UP with a touchUp method

In the touchStart method, we start by creating a new Path and a new FingerPath Objects. We save the current coordinates (x,y) of the finger of the user and we call the moveTo method of the Path object.

In the touchMove method, we check if the move on the screen if greater than the touch tolerance defined as a constant previously. If yes, we call the quadTo method of the Path Object starting from the last point touched and going to the average position between the first position and the current position.

In the touchUp method, we end the line by calling the lineTo method of the Path object with the last position touched on the screen.

With these methods implemented, you can access to the complete code of the PaintView below :

Implement the Main Activity

Last step is to implement the Main Activity and writing its Java code. In this activity, we just need to make the link between menu displayed to user with options (normal, emboss, blur or clear) offered by the PaintView.

Besides, we need to load a DisplayMetrics object for the Main Activity and the initialize the PaintView Object with it in parameter.

]]>https://www.ssaurel.com/blog/learn-to-create-a-paint-application-for-android/feed/0Learn to create a Luminosity Detector Application on Androidhttps://www.ssaurel.com/blog/learn-to-create-a-luminosity-detector-application-on-android/
https://www.ssaurel.com/blog/learn-to-create-a-luminosity-detector-application-on-android/#respondThu, 01 Jun 2017 06:00:40 +0000http://www.ssaurel.com/blog/?p=1773Android devices have a lot of devices to play with. In this tutorial, we are going to play with the ambient luminosity sensor to create a Luminosity Detector Application for Android devices.

You can enjoy this tutorial in video on YouTube :

To start, we are going to create an ultra simple User Interface for our application. We just need a RelativeLayout in our main layout :

Now, it’s time to write the Java code of the Main Activity of our Luminosity Detector Application. First, we need to get the SensorManager instance by calling getSystemService method with the SENSOR_SERVICE constant in parameter.

Then, we get the default sensor for the Ambient Luminosity sensor by calling the getDefaultSensor method of the SensorManager instance got previously with Sensor.TYPE_LIGHT method in parameter.

We check if the Sensor instance returned is null or no. If it is null, the device doesn’t have an Ambient Luminosity sensor. So, we display a message to alert the user and we quit the application by calling the finish method.

If the device has an Ambient Luminosity sensor, we get the maximum range of the sensor. Then, we create a SensorEventListener implementation to manage the values’ changes of the Ambient Luminosity sensor.

In the onSensorChanged method of our implementation, we get the new value for luminosity in lx. We put this value in the [0, 255] range to be able to change the background color of our main activity according the ambient luminosity. Thus, the background color will become lighter when the ambient luminosity will increase.

The last step is to register our SensorEventListener implementation and the light sensor instance got previously on the SensorManager instance by calling its registerListener. In the onPause method of our activity, we mustn’t forget to unregister this listener by calling the unregisterListener method.

This gives us the following code for the Main Activity of our application :