About this ebook
2020 brought us a new version of Android, Android 11 (code-named “R”)! Each new release brings new opportunities and new challenges for Android developers. Many of the new challenges are extensions of the problems introduced in last year’s Android 10. So, if you are worried about further changes to storage or permissions, or you are nervous about new restrictions being placed on developers, this book is for you!
Mark Murphy
Mark Murphy is a FranklinCovey Senior Consultant who has facilitated content successfully to clients worldwide for the last twenty-nine years. During that time, he also spent eleven years as a founding partner of a small boutique firm specializing in project management consulting. Mark grew up in Colorado and lives in Dallas, Texas.
Read more from Mark Murphy
Elements of Android Jetpack Rating: 0 out of 5 stars0 ratingsThe Leader's Guide to Unconscious Bias Rating: 5 out of 5 stars5/5Exploring Android Rating: 0 out of 5 stars0 ratingsLe Guide du dirigeant: Nos biais inconscients: Corriger ses biais, cultiver ses relations et créer des équipes plus performantes Rating: 0 out of 5 stars0 ratingsElements of Android Room Rating: 0 out of 5 stars0 ratingsElements of Android Q Rating: 0 out of 5 stars0 ratingsTravel Forward Rating: 0 out of 5 stars0 ratingsDumb Luck Rating: 0 out of 5 stars0 ratings
Related to Elements of Android R
Related ebooks
Elements of Android Q Rating: 0 out of 5 stars0 ratingsAndroid Application Security Essentials Rating: 0 out of 5 stars0 ratingsAndroid Security Cookbook Rating: 0 out of 5 stars0 ratingsAndroid For Beginners. Developing Apps Using Android Studio Rating: 4 out of 5 stars4/5Android Hacker's Handbook Rating: 4 out of 5 stars4/5Android Programming For Beginners: The Ultimate Android App Developer's Guide Rating: 0 out of 5 stars0 ratingsAsynchronous Android Rating: 4 out of 5 stars4/5Mastering Android Wear Application Development Rating: 0 out of 5 stars0 ratingsAndroid Studio Cookbook: Design, test, and debug your apps using Android Studio Rating: 4 out of 5 stars4/5Learning Android Forensics Rating: 4 out of 5 stars4/5Testing and Securing Android Studio Applications Rating: 0 out of 5 stars0 ratingsAndroid Studio Giraffe Essentials - Java Edition: Developing Android Apps Using Android Studio 2022.3.1 and Java Rating: 0 out of 5 stars0 ratingsMobile Device Exploitation Cookbook Rating: 0 out of 5 stars0 ratingsAndroid Studio Development Essentials Rating: 5 out of 5 stars5/5XDA Developers' Android Hacker's Toolkit: The Complete Guide to Rooting, ROMs and Theming Rating: 2 out of 5 stars2/5Learning Pentesting for Android Devices Rating: 5 out of 5 stars5/5Android Programming For Beginners: The Simple Guide to Learning Android Programming Fast! Rating: 0 out of 5 stars0 ratingsHacking Android Rating: 5 out of 5 stars5/5Beginning Android Programming with Android Studio Rating: 0 out of 5 stars0 ratingsAndroid App Development For Dummies Rating: 0 out of 5 stars0 ratingsAndroid Studio Electric Eel Essentials - Kotlin Edition: Developing Android Apps Using Android Studio 2022.1.1 and Kotlin Rating: 0 out of 5 stars0 ratingsAndroid for Beginners: Step by Step guide to develop Android App Rating: 0 out of 5 stars0 ratingsMobile Forensics – Advanced Investigative Strategies Rating: 0 out of 5 stars0 ratingsAndroid Studio Ladybug Essentials - Kotlin Edition: Developing Android Apps Using Android Studio Ladybug and Kotlin Rating: 0 out of 5 stars0 ratingsPractical Mobile Forensics Rating: 4 out of 5 stars4/5The Mobile Application Hacker's Handbook Rating: 3 out of 5 stars3/5Neural Network Programming: How To Create Modern AI Systems With Python, Tensorflow, And Keras Rating: 0 out of 5 stars0 ratingsHackercool Dec 2016: 0, #3 Rating: 5 out of 5 stars5/5
Internet & Web For You
Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Cybersecurity For Dummies Rating: 5 out of 5 stars5/5The $1,000,000 Web Designer Guide: A Practical Guide for Wealth and Freedom as an Online Freelancer Rating: 4 out of 5 stars4/5Coding For Dummies Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5UX/UI Design Playbook Rating: 4 out of 5 stars4/5Principles of Web Design Rating: 0 out of 5 stars0 ratingsWeb Design For Dummies Rating: 4 out of 5 stars4/5The Gothic Novel Collection Rating: 5 out of 5 stars5/5More Porn - Faster!: 50 Tips & Tools for Faster and More Efficient Porn Browsing Rating: 3 out of 5 stars3/5HTML in 30 Pages Rating: 5 out of 5 stars5/5Learn NodeJS in 1 Day: Complete Node JS Guide with Examples Rating: 3 out of 5 stars3/52022 Adobe® Premiere Pro Guide For Filmmakers and YouTubers Rating: 5 out of 5 stars5/5Publishing E-Books For Dummies Rating: 4 out of 5 stars4/5Kill All Normies: Online Culture Wars From 4Chan And Tumblr To Trump And The Alt-Right Rating: 3 out of 5 stars3/5Notion for Beginners: Notion for Work, Play, and Productivity Rating: 4 out of 5 stars4/5How to Be Invisible: Protect Your Home, Your Children, Your Assets, and Your Life Rating: 4 out of 5 stars4/5SEO For Dummies Rating: 4 out of 5 stars4/548 Really Useful Web Sites Rating: 5 out of 5 stars5/5Build a WordPress Website From Scratch 2024: WordPress 2024 Rating: 0 out of 5 stars0 ratingsMaking TikTok Videos Rating: 5 out of 5 stars5/5Get Into UX: A foolproof guide to getting your first user experience job Rating: 4 out of 5 stars4/5Advanced Web Development with React: SSR and PWA with Next.js using React with advanced concepts Rating: 0 out of 5 stars0 ratingsCOMPUTER SCIENCE FOR ROOKIES Rating: 0 out of 5 stars0 ratingsWordPress For Dummies Rating: 0 out of 5 stars0 ratings
Reviews for Elements of Android R
1 rating0 reviews
Book preview
Elements of Android R - Mark Murphy
Table of Contents
Headings formatted in bold-italic have changed since the last version.
Preface
The Book’s Prerequisites
What’s New in the Final Version?
Warescription
Source Code and Its License
Creative Commons and the Four-to-Free (42F) Guarantee
Acknowledgments
Storage Shifts
Recapping What Happened in Android 10
Let’s Do the Time Warp
Extending the Opt-Out
Raw Paths Support
Hey, What About Writing?
SAF Restrictions
All Files Access
MediaStore Modifications
Recapping What We Got in Android 10
Getting the Right Uri
Batched Access
Permission Permutations
One-Time Permissions
Multiple Rejections = Denial
Background Location Changes
Automatic Permission Removal
Auditing Alternatives
Data Access Auditing
Application Exits
Package Visibility
The Way Things Were
Social Distancing for Apps
Whitelisting
Escaping the Sandbox
Effects and Ramifications
So… Why Bother?
Logging What Was Filtered
Sharing UIs
UI Embedding: The Classic Approaches
What Android 11 Offers
How to Share
Enabling Input
Conversations and Bubbles
From Chat Heads
to Bubbles
The Basics of Conversations
The Basics of Bubbles
Security Stuff
New Foreground Service Types
BiometricPrompt and Weak Biometrics
Toast Restrictions
Further CA Certificate Restrictions
Device Controls
The High-Level View
Elements of a Control Tile
Flow… But Not That Flow
Taking Control of the Situation
Other APIs
Other Changes of Note
Stuff That Might Break You
Stuff That Might Interest You
Preface
Thanks!
Thanks for your continued interest in Android! Android advances year after year, and 2020’s Android 11 (R) continues that pattern. Many developers ignore new Android versions until some concrete problem causes them grief. Hopefully, you are reading this in advance of when Android 11 ships to lots of devices, so you can head off any problems before they turn into customer complaints.
(on the other hand, if you are reading this in response to Android 11 customer complaints… sorry!)
And thanks for your interest in this book and CommonsWare’s overall line of Android books!
The Book’s Prerequisites
This book is designed for developers with 1+ years of Android app development experience. If you are fairly new to Android, please consider reading Elements of Android Jetpack, Exploring Android, or both, before continuing with this book.
Also note that this book’s examples are written in Kotlin.
What’s New in the Final Version?
This book is almost unchanged from the previous version.
Warescription
If you purchased the Warescription, read on! If you obtained this book from other channels, feel free to jump ahead.
The Warescription entitles you, for the duration of your subscription, to digital editions of this book and its updates, in PDF, EPUB, and Kindle (MOBI/KF8) formats, plus the ability to read the book online at the Warescription Web site. You also have access to other books that CommonsWare publishes during that subscription period.
Each subscriber gets personalized editions of all editions of each title. That way, your books are never out of date for long, and you can take advantage of new material as it is made available.
However, you can only download the books while you have an active Warescription. There is a grace period after your Warescription ends: you can still download the book until the next book update comes out after your Warescription ends. After that, you can no longer download the book. Hence, please download your updates as they come out. You can find out when new releases of this book are available via:
The CommonsBlog
The CommonsWare Twitter feed
Opting into emails announcing each book release — log into the Warescription site and choose Configure from the nav bar
Just check back on the Warescription site every month or two
Subscribers also have access to other benefits, including:
Office hours
— online chats to help you get answers to your Android application development questions. You will find a calendar for these on your Warescription page.
A Stack Overflow bump
service, to get additional attention for a question that you have posted there that does not have an adequate answer.
A discussion board for asking arbitrary questions about Android app development.
Source Code and Its License
The source code in this book is licensed under the Apache 2.0 License, in case you have the desire to reuse any of it.
Copying source code directly from the book, in the PDF editions, works best with Adobe Reader, though it may also work with other PDF viewers. Some PDF viewers, for reasons that remain unclear, foul up copying the source code to the clipboard when it is selected.
Creative Commons and the Four-to-Free (42F) Guarantee
Each CommonsWare book edition will be available for use under the Creative Commons Attribution-Noncommercial-ShareAlike 3.0 license as of the fourth anniversary of its publication date, or when 4,000 copies of the edition have been sold, whichever comes first. That means that, once four years have elapsed (perhaps sooner!), you can use this prose for non-commercial purposes. That is our Four-to-Free Guarantee to our readers and the broader community. For the purposes of this guarantee, new Warescriptions and renewals will be counted as sales of this edition, starting from the time the edition is published.
This edition of this book will be available under the aforementioned Creative Commons license on 1 November 2024. Of course, watch the CommonsWare Web site, as this edition might be relicensed sooner based on sales.
For more details on the Creative Commons Attribution-Noncommercial-ShareAlike 3.0 license, visit the Creative Commons Web site
Note that future editions of this book will become free on later dates, each four years from the publication of that edition or based on sales of that specific edition. Releasing one edition under the Creative Commons license does not automatically release all editions under that license.
Acknowledgments
The author would like to thank the Google team responsible for Android 11.
Storage Shifts
Android 10 introduced what Google calls scoped storage
and what the author of this book called the death of external storage
.
Android 11 tweaks scoped storage some more, improving things in some areas and causing new and exciting challenges in others.
Recapping What Happened in Android 10
Before we dive into the Android 11 changes to scoped storage, let’s quickly review what happened in Android 10.
You can learn more about scoped storage in Android 10 in the The Death of External Storage
chapter of Elements of Android Q!
Limited Filesystem Access
While apps can still use getExternalFilesDir() and other methods on Context to work with external and removable storage, everything else has been blocked. Notably, the methods on Environment like getExternalStorageDirectory() and getExternalStoragePublicDirectory() are deprecated. And, if you try to use those directories, you will find that your app lacks access, even if you hold READ_EXTERNAL_STORAGE and/or WRITE_EXTERNAL_STORAGE.
Roughly speaking, there are three alternatives for addressing this limitation.
Alternative #1: Storage Access Framework
For general-purpose content, Google expects you to use the Storage Access Framework:
ACTION_OPEN_DOCUMENT to have the user choose a piece of content
ACTION_CREATE_DOCUMENT to create a new piece of content in a user-chosen location
ACTION_OPEN_DOCUMENT_TREE to have the user choose a document tree
(e.g., a directory) that you can then use for reading and writing
The actual mechanics of the Storage Access Framework did not change in Android 10, merely its importance.
Alternative #2: MediaStore
For apps that work with media and wish to place content in common media locations, MediaStore is still an option. However, the behavior of MediaStore changed some in Android 10 and again in Android 11 — we will explore that more in the next chapter.
Alternative #3: Opt Out of the Change
You could add android:requestLegacyExternalStorage=true
to the legacy
storage model. In other words, android:requestLegacyExternalStorage=true
has your app running on Android 10 behave much as it would on Android 9.
Alternatively, simply having a targetSdkVersion below 29 would give you the same effect.
Let’s Do the Time Warp
Back