1 00:00:03,740 --> 00:00:08,960 G'day, welcome back everyone. Our app's coming along but we're going to take a 2 00:00:08,960 --> 00:00:14,150 break from adding new features. Instead, we'll review what we've got, and make 3 00:00:14,150 --> 00:00:18,950 sure it works on the Android versions that we're supporting. Remember, we're 4 00:00:18,950 --> 00:00:25,310 supporting all Android versions from API 17 onwards, so really, we should have been 5 00:00:25,310 --> 00:00:32,390 testing on, at least, an API 17 emulator, as we went along. I strongly suggest that 6 00:00:32,390 --> 00:00:37,100 you do that. Once you're ready to release your app, test on a whole range of 7 00:00:37,100 --> 00:00:42,440 emulators. You can see when each API changed from the documentation, so you 8 00:00:42,440 --> 00:00:47,269 should test on a range of versions, prior to the introduction of each feature that 9 00:00:47,269 --> 00:00:53,539 your app uses. To see what I mean, let's have a look at the API documentation for 10 00:00:53,540 --> 00:01:04,060 the toolbar at developer.android.com/reference/android/widget/toolbar.html 11 00:01:04,060 --> 00:01:07,520 Notice at the top right of the page, it mentions 12 00:01:07,520 --> 00:01:12,950 that the tool bar class was added in API 21. So as well as testing with our 13 00:01:12,950 --> 00:01:18,549 minimum SDK of 17, it's also worth checking on API 20 and 14 00:01:18,549 --> 00:01:25,460 API 21, in the emulators; the ones before and after the toolbar was added. Ideally, 15 00:01:25,460 --> 00:01:30,560 you test on every version from your minimum up to the most recent. If you 16 00:01:30,560 --> 00:01:34,909 have to cut corners, though, then pick a set of emulators that includes versions 17 00:01:34,909 --> 00:01:40,189 before major features were introduced. While developing your app, test each new 18 00:01:40,189 --> 00:01:47,780 feature in your minimum SDK. We're going to run our app on an API 17 emulator. 19 00:01:47,780 --> 00:02:00,900 Of course, it's not going to work, otherwise I wouldn't be devoting an entire video to this 20 00:02:00,900 --> 00:02:07,060 It runs, so there's a start. I'll add a few tasks to give us some to work with. 21 00:02:07,060 --> 00:02:21,000 I'll use my highly original naming of task 1 task 2 and task 3. 22 00:02:21,099 --> 00:02:28,829 Editing a task in portrait also works fine. Saving the task updates the list. 23 00:02:34,560 --> 00:02:45,960 The problem is in the About dialog. Use the menu to display About TaskTimer. 24 00:02:45,960 --> 00:02:52,360 The email address is a clickable link, and clicking it launches the device's email program, 25 00:02:52,360 --> 00:02:57,700 at least, that's what should happen. 26 00:02:57,700 --> 00:03:00,240 Unfortunately, Google now blocks 27 00:03:00,240 --> 00:03:06,960 the old email app that's installed on these API 17 emulators for security reasons. 28 00:03:06,960 --> 00:03:10,800 Because the emulator can't access the Play Store, apps don't get 29 00:03:10,800 --> 00:03:17,000 updated, and you'll find problems like this on the older emulators. 30 00:03:17,000 --> 00:03:23,580 You can try the instructions at support.google.com/mail/answers, 31 00:03:23,580 --> 00:03:28,540 and then the number you can see in the URL, to configure the email client manually, 32 00:03:28,540 --> 00:03:33,580 but, please don't ask us to help configure your email. 33 00:03:33,580 --> 00:03:35,169 If you do setup your email 34 00:03:35,169 --> 00:03:42,640 client manually, the To address field is automatically filled in from the link we clicked. 35 00:03:42,640 --> 00:03:45,500 So that works fine. 36 00:03:45,500 --> 00:03:50,040 If we go back to the About dialogue, we'll see that the 37 00:03:50,040 --> 00:03:56,420 link is not clickable. Now that was showing as a link in the API 28 emulator, 38 00:03:56,420 --> 00:04:01,440 so we've got a compatibility problem here. The problem's down to the way URLs 39 00:04:01,440 --> 00:04:06,780 were parsed out of the textView contents, in earlier Android versions, 40 00:04:06,780 --> 00:04:13,120 and unfortunately, this particular URL isn't going to work. We could make the link 41 00:04:13,120 --> 00:04:20,548 clickable by editing the strings.xml file in res/values. 42 00:04:28,240 --> 00:04:34,040 Find the about_weblink tag, 43 00:04:34,040 --> 00:04:39,190 and add dot com to the end of the URL. 44 00:04:42,780 --> 00:04:51,200 Run the app again, 45 00:04:51,200 --> 00:04:56,600 and now the link is clickable and it launches the browser. 46 00:04:58,300 --> 00:05:04,100 Unfortunately, it's the wrong URL so the page isn't found, but the browser did 47 00:05:04,100 --> 00:05:09,380 start up. Of course, this assumes that the browser works on the device, so if 48 00:05:09,380 --> 00:05:13,520 nothing happens when you tap the link, make sure the browser does start from 49 00:05:13,520 --> 00:05:19,580 the launch screen. Some of the older emulators do have problems running the browser. 50 00:05:19,580 --> 00:05:24,540 If your URL has a top-level domain that was recognized back then, dot com, 51 00:05:24,540 --> 00:05:32,820 dot jp, dot co.uk or dot au, for example, then the link will be clickable. 52 00:05:32,820 --> 00:05:38,180 You may see a connection problem message: couldn't establish a secure connection. 53 00:05:38,180 --> 00:05:42,470 That's down to the certificates on the emulator, and it's another problem we've got 54 00:05:42,470 --> 00:05:44,810 when using old devices that can't 55 00:05:44,810 --> 00:05:50,780 receive updates. An API 17 physical device should work fine. I'll undo the 56 00:05:50,780 --> 00:05:55,840 change I made in strings.xml before I forget 57 00:05:58,700 --> 00:06:03,500 So, how are we going to fix this problem, and should we? 58 00:06:03,500 --> 00:06:09,580 At some point, you'll have to decide just how much support you're going to provide for older devices, 59 00:06:09,580 --> 00:06:14,260 and whether it's worth risking introducing bugs to support them. 60 00:06:14,260 --> 00:06:19,640 Users can still see the URL on older devices, before API 21, 61 00:06:19,640 --> 00:06:24,830 they just can't click it to launch the browser. The URL will be clickable on API 21 62 00:06:24,830 --> 00:06:31,970 and above, which is currently 85% of the devices out there. If you want to fix 63 00:06:31,970 --> 00:06:37,460 it, one approach could be to use another TextView for the URL. The current TextView 64 00:06:37,460 --> 00:06:41,689 would just say: instructions available at, and you'd 65 00:06:41,689 --> 00:06:46,550 add an onClickListener to the new URL TextView. You can then 66 00:06:46,550 --> 00:06:51,740 launch the browser with the URL, using an intent, and we saw how to do that in the 67 00:06:51,740 --> 00:06:56,419 YouTube app. If you guessed that I'm telling you all this because it's time 68 00:06:56,419 --> 00:07:02,360 for a challenge, you're right. Change our app so that it allows the URL 69 00:07:02,360 --> 00:07:08,629 to be clickable in all Android versions, from API 17 onwards. We've seen how to 70 00:07:08,629 --> 00:07:13,939 create different resource files for different versions of Android. We used the 71 00:07:13,939 --> 00:07:21,020 values/styles resource file when we created an API 21 version, but the same 72 00:07:21,020 --> 00:07:26,569 thing applies to any resource, including layouts. We've also seen how to include 73 00:07:26,569 --> 00:07:33,439 one layout file inside another - activity_main includes content_main, 74 00:07:33,439 --> 00:07:38,059 for example - if you choose to keep the version-specific bits 75 00:07:38,059 --> 00:07:44,060 to a minimum. One thing you'll need to know when using an intent to launch the 76 00:07:44,060 --> 00:07:52,610 browser, is that the URL must start with http:// or https://. 77 00:07:52,610 --> 00:07:58,940 A bit of googling will show examples of passing a URL in the intent. 78 00:07:58,940 --> 00:08:04,300 Your solution shouldn't crash if an invalid URL's provided in the strings 79 00:08:04,310 --> 00:08:09,529 resource file. Here's a tip: If you can't launch the browser from the launch 80 00:08:09,529 --> 00:08:18,520 screen on your API 17 emulator, delete the emulator and create a new one. 81 00:08:26,280 --> 00:08:32,780 So that's your challenge. I'll stop the video here and go over to my solution in the next video. 82 00:08:32,780 --> 00:08:35,880 I'll see you in that one.