Tag: development

Android Accessibility – Making your app Switch Access Compatible

Android Accessibility – Making your app Switch Access Compatible

I received an email a few days ago, where I had a request for the Book Dash Android app to support “Switch Access”. To be honest, I had no idea what this email meant. My first thought was, “Hey, this will never run on a Nintendo Switch” but I realised that this probably wasn’t what they were requesting. After doing a bit more research on what exactly Switch Access is in Android, I realised there isn’t a lot of information around the Android Accessibility feature. Hopefully after reading through this blog post you will be interested in making sure your app is Switch Access compatible.

What is Accessibility?

Accessibility refers to the design of products, devices, services, or environments for people who experience disabilities (ref). For example, some people may be visually impaired and use a service like TalkBack on their device, which speaks out everything on their screen. Some people may enlarge the size of the font of their phone so they can read it clearly. Whilst others might suffer from muscle conditions that prevent them from being able to use the touch screen. This is where Switch Access is meant to help.

What is Android Switch Access?

Switch Access allows users with limited dexterity to use their Android device without using the touch screen. Users typically would use a device similar to the one pictured below to navigate the user interface of their phone.

Switch Access Android
Typical Switch Device

Some switches have one button, others have two buttons or more. Switch Access can be configured to use a keyboard, a device like the one pictured above or built-in buttons on your device such as the volume up and volume down key.

Here is a video explaining how it works:

Great, we’ve now seen how it works, lets try use it on our app.

Enabling Switch Access for Testing

In order to test our apps with Switch Access, we need to enable it. In order to enable it you need to do the following:

  1. Open Settings on your device.
  2. Open the “Accessibility” section.
  3. There should be a service listed called “Switch Access”. Select this service. Before enabling the service, click on the “Settings” for the service. Click “Assign Switches for Scanning”. Here is where you will map certain key events to “Next” and “Select” action.

    Switch Access Settings
    Switch Access Settings
  4. Click “Select”, and then press the key you want to map to the “Select” function. I pressed the “Volume Down” button. Repeat this for the “Next” action, I used the “Volume Up” for the “Next” action but you can use any key you wish.

    Switch Access Android - Assign action to button
    Switch Access Assign Action to Button
  5. Once you have done this, click back and enable “Switch Access”.

We can now navigate through our phone using the volume up and down buttons.

How do I make my app Switch Access compatible?

This is the part that was a mystery that I was battling to solve myself. No amount of Googling got me the result I was looking for, so hopefully my insights can help you achieve compatibility for your apps.

TL;DR: Make sure views that are clickable are selectable and reachable by a keyboard. Make sure views that require gestures can also be properly navigated to without using the required gesture.

Unfortunately there is no “enable this flag and switch access will work” solution to this problem. After using the Book Dash app with Switch Access enabled, I realised there were a few places that didn’t work well with the service enabled.

Switch Access problems in Book Dash

1. Inability to turn a page of the book

The screen that displays the book for reading is in a ViewPager, which means users have to swipe to get to the next page. This was intuitive for me whilst using the touch screen, but not whilst using it with Switch Access. There was no way to turn the page of the book without swiping on the screen. 

The solution for my ViewPager gesture scrolling, was to add click listeners onto each page of the book to go to the next and previous page of the book. I then added “focusable” fields onto the views that had click listeners attached. The following lines were added to each page container (with the click listeners pointing to the correct logic):

Switch Access Android - Navigate and Turn pages
Switch Access Android – Navigate and Turn pages

2. Two clickable areas on the download button

Another example in the Book Dash app was the Download Book button which had two clickable areas. Accessing it using Switch Access caused a bit of frustration, as a secondary dialog showed up asking which one to select.

Multiple clickable areas on download button - Switch Access Android
Multiple clickable areas on download button

The solution for this issue was to remove android:clickable=”true” on the outer view, as the custom view already defined a clickable attribute. Simple fix, but saves users a lot of frustration!

If you want to see more code, check out the open source Github repository for more information.


Enabling Switch Access and testing your app with it on allows you to make your app accessible for users with limited dexterity. This is vitally important if you want to make a high quality, accessible app. In the next few posts we will be looking into other small improvements to make the app more accessible.

Make sure to subscribe to this blog to follow the journey of making Book Dash more accessible. Have something to add? Let me know on Twitter.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Understanding Battery Usage in your Android App

Understanding Battery Usage in your Android App

Developing an android app can be a difficult and daunting task. There is so much to think about and a lot of the time battery usage is not very high on the list of things to remember. However, it is one of the most important things you need to consider. If your app is draining your user’s battery leaving them with a dead phone, the chances of them uninstalling and never using it again are VERY high. Take this guy for example:

Battery Historian - Understanding battery usage in your android app - App Reviews


He is clearly not happy with this app. In this blog post, we will take a look at Battery Historian and also provide some tips on how to avoid draining a user’s battery.

What is Battery Historian?

Battery Historian is a tool that displays information about your phone’s battery usage in HTML form. It provides a way to analyse the battery usage by showing you information like:

  • What app is in the foreground
  • What apps requested a wake lock and how long the phone was awake for
  • When the mobile radio was in use
  • When the GPS is active

How do I use Battery Historian?

  1. Download and install Go
  2. Follow the instructions on the Github page to set up the battery historian.
  3. Plug in your device and run adb bugreport > bugreport.txt in terminal. This will take a couple of minutes.
  4. Run battery historian. Open localhost:9999 in a browser and select the bugreport.txt. You will then see the battery historian output.
Battery Historian - Understanding battery usage in your android app
Battery Historian 2.0 Graph

You can see from this graph that it shows the battery level and the time. The graph also highlights information like if the phone was in Doze Mode, the charging status and lots of other information. This graph shows my device going from 100% at 7AM to about 10% at 12PM.

Battery Historian - Understanding battery usage in your android app - App Stats
App Stats Tab

There is also information regarding specific apps if you want to select your app and see how it is performing. Navigate to “App Stats” and then select your app from the drop down. You can see some useful information such as how much time the app was running for, the data usage and a lot more information.

This tool is very useful for figuring out what resources the apps are using and figuring out how much time they spend in the background even if you don’t use them.

Some tips for improving Battery Usage in your Android App

  • Avoid wake locks if possible.
  • Batch up cellular operations so as to avoid waking up the device every few seconds.
  • Schedule unimportant operations until the user has plugged into a charger and on WiFi. Things like analytics and logging don’t need to happen in real time.
  • Don’t download data if you don’t need to. Try adjust the queries required when using mobile data vs WiFi.
  • Use the system’s built-in options for background processing – such as the JobScheduler API or the SyncAdapters to sync content only when needed.
  • Remove unnecessary background processes if they are not needed.
  • Test your app on a really low end device for a day and see how/if it runs the battery down.
  • Be careful with location updates. The more you request, the more battery you will use. See more here.
  • Join the Android Performance Patterns Google Plus community and read the official docs about improving battery life.

What tips do you have for reducing the amount of battery usage in your application?

Android SQLite Database – How to use onUpgrade() correctly

Android SQLite Database – How to use onUpgrade() correctly

After reading this blog post (and a few others) on how to use the onUpgrade() method for your Android SQLite Database, I thought I should share my experience about how to correctly upgrade your database. It will also be beneficial to highlight why the final solution listed in that blog post would also fail at some point for some scenarios. The post explains quite well the drawbacks of some of the solutions that I also went through, but their final solution can also leave you in trouble.

Read More Read More