G'day, welcome back everyone. Our app's coming along but we're going to take a
break from adding new features. Instead, we'll review what we've got, and make
sure it works on the Android versions that we're supporting. Remember, we're
supporting all Android versions from API 17 onwards, so really, we should have been
testing on, at least, an API 17 emulator, as we went along. I strongly suggest that
you do that. Once you're ready to release your app, test on a whole range of
emulators. You can see when each API changed from the documentation, so you
should test on a range of versions, prior to the introduction of each feature that
your app uses. To see what I mean, let's have a look at the API documentation for
the toolbar at developer.android.com/reference/android/widget/toolbar.html
Notice at the top right of the page, it mentions
that the tool bar class was added in API 21. So as well as testing with our
minimum SDK of 17, it's also worth checking on API 20 and
API 21, in the emulators; the ones before and after the toolbar was added. Ideally,
you test on every version from your minimum up to the most recent. If you
have to cut corners, though, then pick a set of emulators that includes versions
before major features were introduced. While developing your app, test each new
feature in your minimum SDK. We're going to run our app on an API 17 emulator.
Of course, it's not going to work, otherwise I wouldn't be devoting an entire video to this
It runs, so there's a start. I'll add a few tasks to give us some to work with.
I'll use my highly original naming of task 1 task 2 and task 3.
Editing a task in portrait also works fine. Saving the task updates the list.
The problem is in the About dialog. Use the menu to display About TaskTimer.
The email address is a clickable link, and clicking it launches the device's email program,
at least, that's what should happen.
Unfortunately, Google now blocks
the old email app that's installed on these API 17 emulators for security reasons.
Because the emulator can't access the Play Store, apps don't get
updated, and you'll find problems like this on the older emulators.
You can try the instructions at support.google.com/mail/answers,
and then the number you can see in the URL, to configure the email client manually,
but, please don't ask us to help configure your email.
If you do setup your email
client manually, the To address field is automatically filled in from the link we clicked.
So that works fine.
If we go back to the About dialogue, we'll see that the
link is not clickable. Now that was showing as a link in the API 28 emulator,
so we've got a compatibility problem here. The problem's down to the way URLs
were parsed out of the textView contents, in earlier Android versions,
and unfortunately, this particular URL isn't going to work. We could make the link
clickable by editing the strings.xml file in res/values.
Find the about_weblink tag,
and add dot com to the end of the URL.
Run the app again,
and now the link is clickable and it launches the browser.
Unfortunately, it's the wrong URL so the page isn't found, but the browser did
start up. Of course, this assumes that the browser works on the device, so if
nothing happens when you tap the link, make sure the browser does start from
the launch screen. Some of the older emulators do have problems running the browser.
If your URL has a top-level domain that was recognized back then, dot com,
dot jp, dot co.uk or dot au, for example, then the link will be clickable.
You may see a connection problem message: couldn't establish a secure connection.
That's down to the certificates on the emulator, and it's another problem we've got
when using old devices that can't
receive updates. An API 17 physical device should work fine. I'll undo the
change I made in strings.xml before I forget
So, how are we going to fix this problem, and should we?
At some point, you'll have to decide just how much support you're going to provide for older devices,
and whether it's worth risking introducing bugs to support them.
Users can still see the URL on older devices, before API 21,
they just can't click it to launch the browser. The URL will be clickable on API 21
and above, which is currently 85% of the devices out there. If you want to fix
it, one approach could be to use another TextView for the URL. The current TextView
would just say: instructions available at, and you'd
add an onClickListener to the new URL TextView. You can then
launch the browser with the URL, using an intent, and we saw how to do that in the
YouTube app. If you guessed that I'm telling you all this because it's time
for a challenge, you're right. Change our app so that it allows the URL
to be clickable in all Android versions, from API 17 onwards. We've seen how to
create different resource files for different versions of Android. We used the
values/styles resource file when we created an API 21 version, but the same
thing applies to any resource, including layouts. We've also seen how to include
one layout file inside another - activity_main includes content_main,
for example - if you choose to keep the version-specific bits
to a minimum. One thing you'll need to know when using an intent to launch the
browser, is that the URL must start with http:// or https://.
A bit of googling will show examples of passing a URL in the intent.
Your solution shouldn't crash if an invalid URL's provided in the strings
resource file. Here's a tip: If you can't launch the browser from the launch
screen on your API 17 emulator, delete the emulator and create a new one.
So that's your challenge. I'll stop the video here and go over to my solution in the next video.
I'll see you in that one.