The device detection mini app

To make this app, create a new project and call it Device Detection. Delete the default Hello world! widget. Drag Button onto the top of the screen and set its onClick property to detectDevice. We will code this method in a minute.

Drag two LargeText widgets onto the layout and set their id properties to txtOrientation and txtResolution, respectively. You should now have a layout that looks something like this:

The device detection mini app

Add the following members just after the MainActivity class declaration to hold references to our two TextView widgets:

private TextView txtOrientation;
private TextView txtResolution;

Now, in the onCreate method ...

Get Android Programming for Beginners now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.