10/31/17

Announcing Fast Pair - effortless Bluetooth pairing for Android


Posted by Ritesh Nayak M and Ronald Ho, Product Managers


Today we're announcing Fast Pair, a hassle-free process to pair your Bluetooth
devices on all supported Android devices running Google Play services 11.7+ with
compatibility back to Marshmallow (Android 6.0). Fast Pair makes discovery &
pairing of Bluetooth devices easy and is currently rolling out to Android 6.0+
devices. You can try this out with Google Pixel Buds
or Libratone's
Q Adapt On-Ear
, Bose® QuietComfort 35 II, and soon on Plantronics Voyager 8200 series wireless headsets.




Ease of use, speed and security are the design principles driving the Fast Pair
specification. Fast Pair uses BLE (Bluetooth Low Energy) for advertising and
discovery and uses classic Bluetooth for pairing. Here's what a Fast Pair flow
looks like:



  1. Turn on a Fast Pair-enabled device and put it in pairing mode.

    • Android scans for BLE broadcasts in close proximity of the user's phone and
      discovers a Fast Pair packet (provided Bluetooth and Location is turned on).

    • This packet is sent to our servers to get back the device's product image,
      product name and companion app (if there is one).



  2. The user receives a high priority notification asking them to "Tap to pair" to
    the device. The notification contains the product name and image.

  3. When the user taps on the notification, we use classic Bluetooth to
    establish a connection.

  4. A success notification is shown which contains a link to
    download the companion app (if there is one).


Imagine doing all of this without ever fumbling with Bluetooth settings. Users get a seamless and secure pairing
experience and confidence that they're connecting to the right product.
Manufacturers get their brand, device name and companion app in front of the
users.


Thanks to a couple of our partners who have been instrumental in prototyping and
testing this spec, and whose feedback has been invaluable to the Fast Pair
effort. If you are a Bluetooth accessory manufacturer and want to adopt Fast
Pair for your device, please reach
out to us
.


Plantronics is an audio pioneer and a global leader in the communications
industry. From Unified Communications and customer service ecosystems, to data
analytics and Bluetooth headsets, Plantronics delivers high-quality
communications solutions that customers count on today, while relentlessly
innovating on behalf of their future. For more information visit plantronics.com



Libratone is on a mission to liberate sound and to expand peoples'
experiences with music in the era of streaming. Founded in 2009 in Denmark,
Libratone is one of the first audio companies to consider the aesthetics of
speakers – to move them out of the corner of the room and into the center and
onward, for the consumer on the move. For more information visit libratone.com




Read more

10/30/17

GNSS Analysis Tools from Google

Posted by Frank van Diggelen, Software Engineer


Last year in Android Nougat, we introduced APIs for retrieving Global
Navigation Satellite System (GNSS) Raw measurements from Android devices. This
past week, we publicly released href="https://developer.android.com/guide/topics/sensors/gnss.html#analyze">GNSS
Analysis Tools to process and analyze these measurements.



Android powers over 2 billion devices, and Android phones are made by many
different manufacturers. The primary intent of these tools is to enable device
manufacturers to see in detail how well the GNSS receivers are working in each
particular device design, and thus improve the design and GNSS performance in
their devices. However, with the tools publicly available, there is also
significant value to the research and app developer community.


How to use the tool



The GNSS Analysis Tool is a desktop application that takes in raw the GNSS
Measurements logged from your Android device as input.




This desktop application provides interactive plots, organized into three
columns showing the behavior of the RF, Clock, and Measurements. This data
allows you to see the behavior of the GNSS receiver in great detail, including
receiver clock offset and drift to the order of 1 nanosecond and 1 ppb and
measurement errors on a satellite-by-satellite basis. This allows you to do
sophisticated analysis at a level that, until now, was almost inaccessible to
anyone but the chip manufacturers themselves.




The tools support multi-constellation (GPS, GLONASS, Galileo, BeiDou and QZSS)
and multi-frequency. The image below shows the satellite locations for L1, L5,
E1 and E5 signals tracked by a dual frequency chip.




The tools provide an interactive control screen from which you can manipulate
the plots, shown below. From this control screen, you can change the background
color, enable the Menu Bars for printing or saving, and select specific
satellites for the plots.



Receiver test report



The tools also provide automatic test reports of receivers. Click "Make Report"
to automatically create the test report. The report evaluates the API
implementation, Received Signal, Clock behavior, and Measurement accuracy. In
each case it will report PASS or FAIL based on the performance against known
good benchmarks. This test report is primarily meant for the device
manufacturers to use as they iterate on the design and implementation of a new
device. A sample report is shown below.




Our goal with providing these Analysis Tools is to empower device manufacturers,
researchers, and developers with data and knowledge to make Android even better
for our customers. You can visit the GNSS
Measurement site
to learn more and download this application.


Read more

10/26/17

Android 8.1 Developer Preview

Posted by Dave Burke, VP of Engineering

Today we're giving you an early look at Android 8.1. This update to Android Oreo includes a set of targeted enhancements including optimizations for Android Go (for devices with 1GB or less of memory) and a new Neural Networks API to accelerate on-device machine intelligence. We've also included a few smaller enhancements to Oreo in response to user and developer feedback.

We're bringing you this Developer Preview so you can get your apps ready; we've already been helping device makers prepare for this new version. We recommend starting soon -- we're expecting the final public version href="https://developer.android.com/preview/overview.html">in December.

It's easy to get Android 8.1 Developer Preview on your Pixel or Nexus device. Just enroll in the Android Beta Program -- you'll soon receive an over-the-air update to Android 8.1 beta. If you enrolled previously, you're all set, there's no need to re-enroll. The Developer Preview will be available for href="https://www.blog.google/products/pixel/new-pixel-2/">Pixel 2 and Pixel 2 XL devices, as well as for Pixel, Pixel XL, Pixel C, Nexus 5X, Nexus 6P, and the Android emulator.

What's in Android 8.1?

Android 8.1 includes select new features and developer APIs (API level 27), along with the latest optimizations, bug fixes, and security patches. Some of the new APIs include:

  • Android Go memory optimizations and targeting -- Android 8.1 includes a set of memory optimizations for href="https://android-developers.googleblog.com/2017/05/whats-new-in-android-o-developer.html">Android Go configurations (1GB or less of memory). We've added href="https://developer.android.com/reference/android/content/pm/PackageManager.html#FEATURE_RAM_LOW">new hardware feature constants so you can now target the distribution of your apps and APK splits to normal or low-RAM devices running Android 8.1 and later.

  • Neural Networks API -- as part of our efforts to bring machine intelligence to Android, we've added a href="https://developer.android.com/ndk/guides/neuralnetworks/index.html">Neural Networks API via the NDK. It enables hardware-accelerated inference operations on supported devices. We designed the Neural Networks API as a foundational layer for ML frameworks like TensorFlow Lite -- Google's upcoming cross-platform ML framework for mobile -- as well as Caffe2 and others. Stay tuned for TensorFlow Lite announcements.

  • Autofill enhancements -- we've made it easier for password managers and other Autofill services to use the href="https://developer.android.com/guide/topics/text/autofill.html">Autofill framework. For example, we've added support for more UI customization of the Save dialog, as well as href="https://developer.android.com/reference/android/widget/BaseAdapter.html#setAutofillOptions(java.lang.CharSequence...)">setAutofillOptions() for users to set credit card expiration using a spinner.

  • Shared memory API -- this new API lets apps allocate shared memory for faster access to common data. Apps can map anonymous shared memory and manage protection controls using the href="https://developer.android.com/reference/android/os/SharedMemory.html">SharedMemory API. The API is parcelable, AIDL friendly, and exposes useful features like removing write permissions.


Take a look at href="https://developer.android.com/preview/api-overview.html">Android 8.1 site for more information, including the href="https://developer.android.com/sdk/api_diff/27/changes.html">diff report and updated API reference docs.

Test your apps on Android 8.1

With the consumer launch coming href="https://developer.android.com/preview/overview.html">in December, it's important to test your current app now. This gives users a seamless transition to Android 8.1 when it arrives on their devices.

Just enroll your eligible device in href="http://www.android.com/beta">Android Beta to get the latest update, then install your app from Google Play and test. If you don't have a Pixel or Nexus device, you can set up an Android 8.1 emulator for testing instead. If you notice any issues, fix them and update your app in Google Play right away -- without changing the app's platform targeting.

Build with new features and APIs

When you're ready, take advantage of the new features and APIs in Android 8.1, which we've already finalized as API Level 27. For an overview of what's new, take a look at href="https://developer.android.com/preview/api-overview.html">Android 8.1 for Developers. You can also extend your apps with established Android Oreo features as well, see the href="https://developer.android.com/about/versions/oreo/android-8.0.html">Android Oreo site for details.

If your app uses forms, make sure to test them with href="https://developer.android.com/guide/topics/text/autofill.html">autofill so that users can take advantage of this convenient feature. Enable "Autofill with Google" or a similar service in Settings and test the form fills to make sure they work as expected. We strongly recommend href="https://developer.android.com/guide/topics/text/autofill.html#providing_hints_for_autofill">providing explicit hints about your fields, and also href="https://developers.google.com/identity/smartlock-passwords/android/associate-apps-and-sites">associating your website and mobile app, so that logins can be shared between them.




Speed your development with Android Studio

To build with Android 8.1, we recommend updating to href="https://android-developers.googleblog.com/2017/10/android-studio-30.html">Android Studio 3.0, which is now href="https://developer.android.com/studio/index.html">available from the stable channel. On top of the new app href="https://developer.android.com/studio/profile/android-profiler.html">performance profiling tools, support for the href="http://android-developers.googleblog.com/2017/05/android-announces-support-for-kotlin.html">Kotlin programming language, and Gradle build optimizations, Android Studio 3.0 makes it easier to develop with Android Oreo features like href="https://android-developers.googleblog.com/2017/05/android-instant-apps-is-open-to-all.html">Instant Apps, href="https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html">XML Fonts, href="https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html">downloadable fonts, and href="https://developer.android.com/guide/practices/ui_guidelines/icon_design_adaptive.html">adaptive icons.

We also recommend updating to the href="https://developer.android.com/topic/libraries/support-library/revisions.html?utm_campaign=android_launch_npreview_061516&utm_source=anddev&utm_medium=blog">Android Support Library 27.0.0, which is available from href="https://developer.android.com/studio/build/dependencies.html#google-maven">Google's Maven repository. New in this version are: a href="https://developer.android.com/reference/android/support/content/ContentPager.html">ContentPager library for efficiently loading "paged" data on a background thread; ViewCompat href="https://developer.android.com/reference/android/support/v4/view/ViewCompat.html#getImportantForAutofill(android.view.View)">wrappers for Autofill methods; an href="https://developer.android.com/wear/releases/index.html">AmbientMode headless fragment that improves Wear ambient mode support, fullscreen Trusted Web Activities, and more. See the href="https://developer.android.com/topic/libraries/support-library/revisions.html#27-0-0">version notes for more information.

You can update your project's compileSdkVersion to API 27 to compile against the official Android 8.1 APIs. We also recommend updating your app's targetSdkVersion to API 27 to test with compatibility behaviors disabled. See the href="https://developer.android.com/preview/setup-sdk.html">this guide for details on how to set up your environment to build with Android 8.1.

Publish your updates to Google Play

The Android 8.1 APIs are already final, so we've opened Google Play for apps compiled against or targeting API level 27. When you're ready, you can publish your APK updates in your alpha, beta, or production channels. Make sure that your updated app runs well on Android 8.1 as well as older versions. We recommend using Google Play's href="https://developer.android.com/distribute/engage/beta.html?utm_campaign=android_launch_npreview_061516&utm_source=anddev&utm_medium=blog">beta testing feature to run an alpha test on small group of users, then run a much larger open beta test. When you're ready to launch your update, you can use a href="https://developer.android.com/distribute/best-practices/launch/progressive-updates.html">staged rollout. We're looking forward to seeing your app updates!

Give us your feedback!

As always, your feedback is crucial, so please href="https://developer.android.com/preview/feedback.html">let us know what you think. We've set up different hotlists where you report href="https://issuetracker.google.com/issues/new?component=190602&template=809005">Android platform and tools issues, href="https://issuetracker.google.com/issues/new?component=190602&template=808305">app compatibility issues, and href="https://issuetracker.google.com/issues/new?component=190602&template=809305">third-party SDKs and tools issues. We also have a new hotlist for href="https://issuetracker.google.com/issues/new?component=190602&template=1024216">Neural Networks API issues.

You can also give us feedback through the href="https://plus.google.com/communities/105153134372062985968/stream/755bb91d-c101-4e32-9277-1e560c4e26d2">Android Developer community or href="https://plus.google.com/communities/106765800802768335079">Android Beta community as we work towards the consumer release in December.

Read more

Android Studio 3.0

Posted by Jamal Eason, Product
Manager, Android




Android Studio 3.0 is ready to download today. Announced at Google I/O 2017,
Android Studio 3.0 is a large update focused on accelerating your app
development on Android.



This release of Android Studio is packed with many new updates, but there are
three major feature areas you do not want to miss, including: a new suite of app
profiling tools to quickly diagnose performance issues, support for the Kotlin
programming language, and a new set of tools and wizards to accelerate your
development on the latest Android Oreo APIs.



We also invested time in improving stability and performance across many areas
of Android Studio. Thanks to your feedback during the preview versions of
Android Studio 3.0! If you are looking for high stability, want to build high
quality apps for Android Oreo, develop with the Kotlin language, or use the
latest in Android app performance tools, then you should download Android Studio
3.0 today.



Check out the the list of new features in Android Studio 3.0 below, organized by
key developer flows.



What’s new in Android Studio 3.0

Develop



  • Kotlin Programming Language - As href="https://android-developers.googleblog.com/2017/05/android-announces-support-for-kotlin.html">announced
    at Google I/O 2017, the Kotlin
    programming language is now officially supported for Android development. Kotlin
    is an expressive and concise language that is interoperable with existing
    Android languages and runtimes, which means you can use as little or as much of
    the language in your app as you want. Kotlin is a production-ready language
    used by many popular Android apps on Google Play today.


    This release of Android Studio is the first milestone of bundles the Kotlin
    language support inside the IDE. Many of your favorite features such as code
    completion and syntax highlighting work well this release and we will continue
    to improve the remaining editor features in upcoming release. You can choose to
    add Kotlin to your project using the built-in conversion tool found under
    CodeConvert Java File to Kotlin File, or
    create a Kotlin enabled project with the New Project Wizard. Lean more about
    Kotlin language support
    in Android Studio
    .



Kotlin Language Conversion in Android Studio


  • Java 8 Language features - In Android
    Studio 3.0, we are continuing to improve the support for Java 8 language
    features. With the href="https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html">migration
    to a javac based toolchain, using Java 8 language features in your project
    is even easier. To update your project to support the new Java 8 Language
    toolchain, simply update your Source and Target compatibility
    levels to 1.8 in the Project Structure dialog. href="https://developer.android.com/studio/write/java8-support.html">Learn
    more.


  • Layout Editor - The component tree in the
    Layout Editor has better drag-and-drop view insertions, and a new error
    panel. href="https://developer.android.com/studio/write/layout-editor.html">Learn
    more.


  • Adaptive Icon Wizard - The new wizard
    creates a set of launcher icon assets and provides previews of how your
    adaptive icon will look with different launcher screen icon masks. Support for
    VectorDrawable layers is new for this release. href="https://developer.android.com/studio/write/image-asset-studio.html">Learn
    more.


  • XML Fonts & Downloadable Fonts - If you
    target Android Oreo (API Level 26 and higher) for your Android app, you can now
    add custom fonts & downloadable fonts using XML with Android Studio
    3.0.


  • Android Things Support - Android Studio
    3.0 includes a new set of templates in the New Project wizard and the New Module
    wizard to develop for the Android Things platform. href="https://developer.android.com/things/index.html">Learn more.


  • IntelliJ Platform Update: Android Studio 3.0 includes the
    IntelliJ 2017.1 release, which has features such as Java 8 language refactoring,
    parameter hints, semantic highlighting, draggable breakpoints, enhanced version
    control search, and more. href="https://www.jetbrains.com/idea/whatsnew/#v2017-1">Learn
    more.

Build



  • Instant App Support - With this release of
    Android Studio, you can add href="https://developer.android.com/topic/instant-apps/index.html">Instant
    Apps features to your project. Available forhref="https://android-developers.googleblog.com/2017/05/android-instant-apps-is-open-to-all.html">
    full development earlier this year, Instant Apps are lightweight Android
    apps that your users can immediately run without installation. href="https://developer.android.com/topic/instant-apps/index.html">Learn
    more.


  • Build Speed Improvements - To further
    improve the speed of Gradle for larger scale projects with many modules, we
    introduced a rare breaking API change in the Android Gradle Plugin to
    improve scalability and build times. This change is one of reasons we jumped
    version numbers from Android Studio 2.4 to 3.0. If you depend on APIs provided
    by the previous Gradle plugin you should validate compatibility with the new
    plugin and migrate to the new APIs. To test, update the plugin version in your
    build.gradle file. href="https://developer.android.com/studio/preview/features/new-android-plugin.html">Learn
    more.


  • Google's Maven Repository - To facilitate
    smaller and faster updates, Android Studio 3.0 utilizes Google's Maven
    Repository by default instead of using the Android SDK Manager to find updates
    to Android Support Library, Google Play Services, and Firebase Maven
    dependencies. Used in combination with the latest command line href="https://developer.android.com/studio/intro/update.html#download-with-gradle">SDK
    Manager tool and href="https://developer.android.com/studio/intro/update.html#download-with-gradle">Gradle,
    Continuous Integration builds should migrate to Google's Maven Repository for
    future Maven repository updates. href="https://developer.android.com/studio/build/dependencies.html#google-maven">Learn
    more.

Test & Debug



  • Google Play System Images - We also
    updated the emulator system images for Android Oreo to now include the Google
    Play Store. Bundling in the Google Play store allows you to do end-to-end
    testing of apps with Google Play, and provides a convenient way to keep Google
    Play services up-to-date in your Android Virtual Device (AVD). Just as Google
    Play services updates on physical devices, you can trigger the same updates on
    your AVDs.

    Google Play Store in Android Emulator



    To ensure app security and a consistent experience with physical devices, the
    emulator system images with the Google Play store included are signed with a
    release key. This means you will not be able to get elevated privileges. If you
    require elevated privileges (root) to aid with your app troubleshooting, you can
    use the Android Open Source Project (AOSP) emulator system images that do not
    include Google apps or services. href="https://developer.android.com/studio/run/emulator.html">Learn more.



  • OpenGL ES 3.0 Support in Android Emulator -
    The latest version of the Android Emulator has OpenGL ES 3.0 support
    for Android Oreo system images along with significant improvements in OpenGL ES
    2.0 graphics performance for older emulator system images. href="https://developer.android.com/studio/run/emulator-acceleration.html">Learn
    more.


  • App Bug Reporter in Android Emulator - To
    help in documenting bugs in your app, we have added an easier way to generate a
    bug report with the Android Emulator with all the necessary configuration
    settings and space to capture your repro steps. href="https://developer.android.com/studio/report-bugs.html#emulator-bugs">Learn
    more.


  • Proxy Support in Android - If you use a
    proxy to access the Internet, we have added a user interface to manage the HTTP
    proxy settings used by the emulator. href="https://developer.android.com/studio/run/emulator-networking.html#proxy">Lean
    more.


  • Android Emulator Quick Boot (Canary) - One
    of the most common pain points we hear is that the emulator takes too long to
    boot. To address this concern, we are excited to preview a new feature to solve
    this called Quick Boot, which significantly speeds up your emulator start time.
    Once enabled, the first time you start an AVD a cold boot will occur (just like
    powering on a device), but all subsequent starts are fast and the system is
    restored to the state at which you closed the emulator (similar to waking a
    device). If you want to try it out, ensure you are on the canary update release
    channel and then you will find v26.2.0 of the Android Emulator in the SDK
    Manager. href="https://developer.android.com/studio/preview/emulator.html">Learn
    more.



  • APK Debugging - Android Studio 3.0 allows
    you to debug an arbitrary APK. This functionally is especially helpful for those
    who develop your Android C++ code in another IDE, but want to debug and analyze
    the APK in the context of Android Studio. As long as you have a debuggable
    version of your APK, you can use the new APK Debugging features to analyze,
    profile & debug the APK. Moreover, if you have access to the sources of your
    APK, you can link the source to the APK debugging flow for a higher fidelity
    debugging process. Get started by simply selecting Profile or debug
    APK
    from the Android Studio Welcome Screen or File → Profile or
    debug APK
    . href="https://developer.android.com/studio/preview/features/apk-debugger.html">Learn
    More.


APK Debugging


  • Layout Inspector - In this release we have
    added a few additional enhancements for the Layout Inspector including better
    grouping of properties into common categories, as well as search functionality
    in both the View Tree and Properties Panels. href="https://developer.android.com/studio/debug/layout-inspector.html">Learn
    more.


  • Device File Explorer - The new Device File
    Explorer in Android Studio 3.0 allows you to view the file and directory
    structure of your Android device or emulator. As you are testing your app, you
    can now quickly preview and modify app data files directly in Android Studio.
    Learn
    more
    .


  • Android Test Orchestrator Support - When used with
    AndroidJUnitRunner 1.0 or higher, the Android Gradle plugin 3.0 supports the use
    of the Android Test Orchestrator. The Android Test Orchestrator allows each of
    your app's tests to run within its own href="https://developer.android.com/reference/android/app/Instrumentation.html">Instrumentation.
    href="https://developer.android.com/training/testing/junit-runner.html#using-android-test-orchestrator">Learn
    more.


Optimize


  • Android Profiler - Android Studio 3.0
    includes a brand new suite of tools to help debug performance problems in your
    app. We completely rewrote the previous set of Android Monitor tools, and
    replaced them with the Android Profiler. Once you deploy your app to a running
    device or emulator, click on the Android Profiler tab and you
    will now have access to a real-time & unified view of the CPU, Memory, & Network
    activity for your app. Each of the performance events are mapped to the UI event
    timeline which highlights touch events, key presses, and activity changes so
    that you have more context on when and why a certain event happened. Click on
    each timeline to dig into each performance aspect of your app. href="https://developer.android.com/studio/preview/features/android-profiler.html">Learn
    more.


Android Profiler - Combined timeline view.



CPU Profiler



Memory Profiler



Network Profiler

  • APK Analyzer Improvements - We also
    updated APK Analyzer with additional enhancements to help you further optimize
    the size of your APK. href="https://developer.android.com/studio/build/apk-analyzer.html">Learn
    more.


To recap, Android Studio 3.0 includes these new major features:





Develop


  • Kotlin Language
  • href="https://developer.android.com/studio/write/java8-support.html">Java
    8 Language
  • href="https://developer.android.com/studio/write/layout-editor.html">Layout
    Editor Improvements
  • href="https://developer.android.com/studio/write/image-asset-studio.html">Adaptive
    Icon Wizard
  • href="https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts.html">XML
    Fonts & Downloadable Fonts
  • Android Things
  • Intellij Platform
    Update 2017.1


Build


  • href="https://developer.android.com/topic/instant-apps/index.html">Instant App
    Support
  • href="https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html">Build
    Speed Improvements
  • href="http://developer.android.com/studio/build/dependencies.html#google-maven">Google's
    Maven Repo Change


Optimize


  • CPU
    Profiler

  • href="https://developer.android.com/studio/profile/memory-profiler.html">Memory
    Profiler
  • href="https://developer.android.com/studio/profile/network-profiler.html">Network
    Profiler
  • APK
    Analyzer Improvements


Check out the href="https://developer.android.com/studio/releases/index.html">release
notes for more details.


Getting Started



Download





Test & Debug





If you are using a previous version of Android Studio, you can upgrade to
Android Studio 3.0 today or you can download the update from the official
Android Studio Preview href="https://developer.android.com/studio/preview/index.html">download
page. As mentioned in this blog, there are some breaking Gradle Plugin API
changes to support new features in the IDE. Therefore, you should also update
your Android Gradle plugin version to 3.0.0 in your current project to test and
validate your app project setup.



We appreciate any feedback on things you like, issues or features you would like
to see. If you find a bug or issue, feel free to href="https://source.android.com/source/report-bugs#developer-tools">file an
issue. Connect with us -- the Android Studio development team ‐ on our href="https://plus.google.com/103342515830390186255">Google+ page or on href="http://www.twitter.com/androidstudio">Twitter


Read more

10/20/17

Playtime 2017: Find success on Google Play and grow your business with new Play Console features



Posted by Vineet Buch, Director of Product Management, Google Play Apps & Games







Today we kicked off our annual global Playtime series with back-to-back events in Berlin and San Francisco. Over the next month, we’ll be hearing from many app and game developers in cities around the world. It has been an amazing 2017 for developers on Google Play, there are now more than 8 billion new installs per month globally.
To help you continue to take advantage of this opportunity, we're announcing innovations on Google Play and new features in the Play Console. Follow us on Medium where presenters will be posting their strategies, best practices, and examples to help you achieve your business objectives. As Google Play continues to grow rapidly, we want to help people understand our business. That's why we're also publishing the State of Play 2017 report that will be updated annually to help you stay informed about our progress and how we’re helping developers succeed.
Apps and games on Google Play bring your devices to life, whether they're phones and tablets, Wear devices, TVs, Daydream, or Chromebooks like the new Google Pixelbook. We're making it even easier for people to discover and re-engage with great content on the Play Store.




Recognizing the best

We're investing in curation and editorial to showcase the highest quality apps and games we love. The revamped Editors' Choice is now live in 17 countries and Android Excellence recently welcomed new apps and games. We also continue to celebrate and support indie games, recently announcing winners of the Indie Games Festival in San Francisco and opening the second Indie Games Contest in Europe for nominations.





Discovering great games

We've launched an improved home for games with trailers and screenshots of gameplay and two new browse destinations are coming soon, 'New' (for upcoming and trending games) and 'Premium' (for paid games).





Going beyond installs

We’re showing reminders to try games you’ve recently installed and we’re expanding our successful ‘live operations’ banners on the Play Store, telling you about major in-game events in popular games you’ve got on your device. We're also excited to integrate Android Instant Apps with a 'Try Now' button on store listings. With a single tap, people can jump right into the app experience without installing.


The new games experience on Google Play
The Google Play Console offers tools which help you and your team members at every step of an app’s lifecycle. Use the Play Console to improve app quality, manage releases with confidence, and increase business performance.




Focus on quality

Android vitals were introduced at I/O 2017 and already 65% of top developers are using the dashboard to understand their app's performance. We're adding five new Android vitals and increasing device coverage to help you address issues relating to battery consumption, crashes, and render time. Better performing apps are favored by Google Play's search and discovery algorithms.

We're improving pre-launch reports and enabling them for all developers with no need to opt-in. When you upload an alpha or beta APK, we'll automatically install and test your app on physical, popular devices powered by Firebase Test Lab. The report will tell you about crashes, display issues, security vulnerabilities, and now, performance issues encountered.

When you install a new app, you expect it to open and perform normally. To ensure people installing apps and games from Google Play have a positive experience and developers benefit from being part of a trusted ecosystem, we are introducing a policy to disallow apps which consistently exhibit broken experiences on the majority of devices such as​ crashing,​ closing,​ ​freezing,​ ​or​ ​otherwise​ ​functioning​ ​abnormally. Learn more in the policy center.




Release with confidence

Beta testing lets trusted users try your app or game before it goes to production so you can iterate on your ideas and gather feedback. You can now target alpha and beta tests to specific countries. This allows you to, for example, beta test in a country you're about to launch in, while people in other countries receive your production app. We'll be bringing country-targeting to staged rollouts soon.

We've also made improvements to the device catalog. Over 66% of top developers are using the catalog to ensure they provide a great user experience on the widest range of devices. You can now save device searches and see why a specific device doesn't support your app. Navigate to the device catalog and review the terms of service to get started.




Grow your subscriptions business

At I/O 2017 we announced that both the number of subscribers on Play and the subscriptions business revenue doubled in the preceding year. We're making it easier to setup and manage your subscription service with the Play Billing Library and, soon, new test instruments to simplify testing your flows for successful and unsuccessful payments.

We're helping you acquire and retain more subscribers. You can offer shorter free trials, at a minimum of three days, and we will now enforce one free trial at the app level to reduce the potential for abuse. You can opt-in to receive notifications when someone cancels their subscription and we're making it easier for people to restore a canceled subscription. Account hold is now generally available, where you can block access to your service while we get a user to fix a renewal payment issue. Finally, from January 2018 we're also updating our transaction fee for subscribers who are retained for more than 12 months.




Announcing the Google Play Security Reward Program

At Google, we have long enjoyed a close relationship with the security research community. Today we're introducing the Google Play Security Reward Program to incentivize security research into popular Android apps, including Google's own apps. The program will help us find vulnerabilities and notify developers via security recommendations on how to fix them. We hope to bring the success we have with our other reward programs, and we invite developers and the research community to work together with us on proactively improving Google Play ecosystem's security.




Stay up to date with Google Play news and tips











How useful did you find this blogpost?







Read more

10/19/17

Google Play's Indie Games Contest is back in Europe. Enter now

Posted by Adriana Puchianu, Developer Marketing Google Play

Following href="https://events.withgoogle.com/indie-games-contest-europe/">last year's success, today we're announcing the second annual href="https://events.withgoogle.com/indie-games-contest-2017/">Google Play Indie Games Contest in Europe, expanding to more countries and bigger prizes. The contest rewards your passion, creativity and innovation, and provides support to help bring your game to more people.

Prizes for the finalists and winners

  • A trip to London to showcase your game at the Saatchi Gallery

  • Paid digital marketing campaigns worth up to 100,000 EUR

  • Influencer campaigns worth up to 50,000 EUR

  • Premium placements on Google Play

  • Promotion on Android and Google Play marketing channels

  • Tickets to Google I/O 2018 and other top industry events

  • Latest Google hardware

  • Special prizes for the best Unity games




How to enter the contest

If you're based in one of the 28 eligible countries, have 30 or less full time employees, and published a new game on Google Play after 1 January 2017, you may now be eligible to href="https://events.withgoogle.com/indie-games-contest-2017/">enter the contest. If you're planning on publishing a new game soon, you can also enter by submitting a private beta. Check out all the details in the href="https://events.withgoogle.com/indie-games-contest-2017/terms-conditions/#content">terms and conditions. Submissions close on 31 December 2017.

Up to 20 finalists will showcase their games at an open event at the Saatchi Gallery in London on the 13th February 2018. At the event, the top 10 will be selected by the event attendees and the Google Play team. The top 10 will then pitch to the jury of industry experts, from which the final winner and runners up will be selected.

Come along to the final event

Anyone can register to attend the href="https://events.withgoogle.com/indie-games-contest-2017/final-event/#content">final showcase event at the Saatchi Gallery in London on 13 February 2018. Play some great indie games and have fun with indie developers,industry experts, and the Google Play team.

Enter now

Visit the contest site to href="https://events.withgoogle.com/indie-games-contest-2017/registrations/new/">find out more and enter the Indie Games Contest now.

How useful did you find this blogpost? href="https://docs.google.com/forms/d/e/1FAIpQLScLTlzFd_aV-3rAdBqO1QxwCsuAcDCIM6fJFXyNcyf7zElVXg/viewform?usp=pp_url&entry.753333049=1%E2%98%85+%E2%80%93+Not+at+all&entry.2056663615&entry.646747778=vitalrank-07/17" style="color:gold;">★ href="https://docs.google.com/forms/d/e/1FAIpQLScLTlzFd_aV-3rAdBqO1QxwCsuAcDCIM6fJFXyNcyf7zElVXg/viewform?usp=pp_url&entry.753333049=2%E2%98%85+%E2%80%93+Not+very&entry.2056663615&entry.646747778=vitalrank-07/17" style="color:gold;">★ href="https://docs.google.com/forms/d/e/1FAIpQLScLTlzFd_aV-3rAdBqO1QxwCsuAcDCIM6fJFXyNcyf7zElVXg/viewform?usp=pp_url&entry.753333049=3%E2%98%85+%E2%80%93+Somewhat&entry.2056663615&entry.646747778=vitalrank-07/17" style="color:gold;">★ href="https://docs.google.com/forms/d/e/1FAIpQLScLTlzFd_aV-3rAdBqO1QxwCsuAcDCIM6fJFXyNcyf7zElVXg/viewform?usp=pp_url&entry.753333049=4%E2%98%85+%E2%80%93+Very&entry.2056663615&entry.646747778=vitalrank-07/17" style="color:gold;">★ href="https://docs.google.com/forms/d/e/1FAIpQLScLTlzFd_aV-3rAdBqO1QxwCsuAcDCIM6fJFXyNcyf7zElVXg/viewform?usp=pp_url&entry.753333049=5%E2%98%85+%E2%80%93+Extremely&entry.2056663615&entry.646747778=vitalrank-07/17" style="color:gold;">★
Read more

10/16/17

Fight global hunger with your favorite apps and games on Google Play

Editor's note: Cross-post from The Keyword. If you’re a developer interested in supporting a fundraising cause within your title or if you have a social impact app, let us know



Posted by Maxim Mai, Partner Development Manager, Google Play



We grow enough food to feed everyone on the planet. Yet 815 million people–one
in nine—still go to bed on an empty stomach every day.



On October 16, people from around the world come together for href="http://www.wfp.org/WorldFoodDay">World Food Day, with the goal to
promote awareness and action for those who suffer from hunger and to advocate
for food security and nutritious diets for all.



To raise funds and awareness for this cause, Google Play has joined forces with
12 popular apps and games to create the href="https://play.google.com/store/apps/topic?id=campaign_editorial_worldfoodday17_ep&e=-EnableAppDetailsPageRedesign">Apps
and Games Against Hunger collection available in North and Latin America.



From now until October 21, 100% of revenue from designated in-app purchases made
in Google Play's Apps and Games Against Hunger collection will be donated to
World Food Program USA.



World Food Program USA supports the mission of the href="http://www1.wfp.org/">UN World Food Programme, the leading agency
fighting hunger, by mobilizing individuals, lawmakers and businesses in the U.S.
to advance the global movement to end hunger, feeding families in need around
the world.





These are the 12 global leading apps and games taking part in this special
fundraising collection on Google Play:



href="https://play.google.com/store/apps/details?id=org.sharethemeal.app">ShareTheMeal–Help
children



href="https://play.google.com/store/apps/details?id=com.brainbow.peak.app">Peak–Brain
Games & Training



href="https://play.google.com/store/apps/details?id=es.socialpoint.DragonCity&e=-EnableAppDetailsPageRedesign">Dragon
City



href="https://play.google.com/store/apps/details?id=com.nordcurrent.canteenhd&e=-EnableAppDetailsPageRedesign">Cooking
Fever



href="https://play.google.com/store/apps/details?id=com.kongregate.mobile.throwdown.google&e=-EnableAppDetailsPageRedesign">Animation
Throwdown: TQFC



href="https://play.google.com/store/apps/details?id=com.n3twork.legendary&e=-EnableAppDetailsPageRedesign">Legendary:
Game of Heroes



href="https://play.google.com/store/apps/details?id=com.melesta.coffeeshop&e=-EnableAppDetailsPageRedesign">My
Cafe: Recipes & Stories - World Cooking Game



href="https://play.google.com/store/apps/details?id=com.kabam.bigrobot&e=-EnableAppDetailsPageRedesign">TRANSFORMERS:
Forged to Fight



href="https://play.google.com/store/apps/details?id=com.yodo1.rodeo.safari&e=-EnableAppDetailsPageRedesign">Rodeo
Stampede: Sky Zoo Safari



href="https://play.google.com/store/apps/details?id=com.ludia.jurassicworld&e=-EnableAppDetailsPageRedesign">Jurassic
World™: The Game



href="https://play.google.com/store/apps/details?id=com.kabam.marvelbattle&e=-EnableAppDetailsPageRedesign">MARVEL
Contest of Champions



href="https://play.google.com/store/apps/details?id=com.protostar.sling&e=-EnableAppDetailsPageRedesign">Sling
Kong



Thank you to all our users and developers for supporting World Food Day.


Read more

10/14/17

Effective phone number verification

Posted by Steven Soneff, Identity Product Manager


To build apps that make use of phone numbers, it's often crucial to verify that
the user owns a number. Doing this can be tricky from a UX perspective, not
least in understanding phone number formats in different locales, but also in
providing a verification mechanism that isn't cumbersome or using intrusive
device permissions, such as the ability to read all of a user's SMS.



There are many libraries for efficient pre-built phone authentication, such as
Firebase Phone Auth, but if
you are an advanced developer and need to build this functionality yourself,
Google Play Services has two new APIs that help you obtain a user's phone number
and verify it via SMS without device permissions: the Phone
Selector
and SMS Retriever. Apps like href="https://play.google.com/store/apps/details?id=com.flipkart.android">Flipkart
have seen a 12% increase of success rates in phone number sign-up flows using
these methods.


The
href="https://developers.google.com/identity/sms-retriever/overview">steps
for using these with your server can be seen here:




In this post we'll show the code that you need to provide a phone number
selector to your users, and then use this with the SMS retriever API to request
a verification code from your server that the Android device will automatically
receive and parse with no input from the user.



Note: Before you begin you'll need to build and test this is a
device with a phone number that can receive SMS and runs Google Play services
10.2.x and higher.


Using the Phone Selector to get the number



The first step is to have the user initiate SMS verification from within your
app. Your app might prompt the user to enter a phone number, and you can use the
Phone Selector to make this easier, using code like this:




class="prettyprint">// Construct a request for phone numbers and show the picker
private void requestHint() {
HintRequest hintRequest = new HintRequest.Builder()
.setPhoneNumberIdentifierSupported(true)
.build();

PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(
apiClient, hintRequest);
startIntentSenderForResult(intent.getIntentSender(),
RESOLVE_HINT, null, 0, 0, 0);
}


The HintRequest builder tells Play Services that a phone number identifier is
needed. This is then used to create and start an intent, which will show a Play
Service dialog to the user allowing them to select their phone number to share
with the app. This API does not require any permissions, and displays the
number(s) available on the phone or Google Account for the user to select.





When the user selects a phone number it will be returned to the application in
onActivityResult in E164
format
on devices running the latest version of Play Services. Note that in
some cases, depending on your phone, you may not get a phone number, so be sure
to check if the credential is non-null. If you don't have a number, you'll need
to provide a way for your user to type it in manually.




class="prettyprint">// Obtain the phone number from the result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESOLVE_HINT) {
if (resultCode == RESULT_OK) {
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
// credential.getId(); <-- E.164 format phone number on 10.2.+ devices
}
}
}


At this point you'll have a phone number string for your user. While this is
useful, you'll likely want to verify that the user owns this particular number,
for example to allow them to send or retrieve message with other users or
identifying themselves with this number.


Using the SMS Verification API to verify the number



A simple way to verify phone number ownership is by sending an SMS to the
number, containing a one time verification code, and having them enter that into
your app. The SMS Verification API gives you the ability for the app to listen
for an incoming SMS from which it can parse the code automatically.



To get started, your app will SmsRetrieverClient
with code like this:



class="prettyprint">SmsRetrieverClient client = SmsRetriever.getClient(this /* context */);

Task<Void> task = client.startSmsRetriever();

task.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
// successfully started an SMS Retriever for one SMS message
}
});

task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
});
);


It's pretty simple -- you get an SMS Retriever client and then start a task for
it. The task has an on Success listener as well as an on Failure one to
override. After starting the SMS Retriever, you'd send the user's phone number
to your server and start it's workflow for generating the message and sending it
to that number.



The message needs to be constructed in a specific way. The message must fit in
an SMS message, so it can't be longer than 140 bytes. It needs to start with a
specific prefix: '<#>' or two consecutive zero-width space characters (U+200B).
See the href="https://developers.google.com/identity/sms-retriever/verify">documentation
for your more information. It must end with an 11-character hash that identifies
your app, described below.



Example:



<#> Use 123456 as your verification code in Example App!



FA+9qCX9VSu





The one-time verification code can be any string: you can simply generate a
random number. The message needs to end with a hash that is determined according
to the procedures href="https://developers.google.com/identity/sms-retriever/verify#computing_your_apps_hash_string">here.
Google Play services will use this hash to determine which app the verification
message is for. You only need to generate this hash once for your app package
and signing certificate: it won't change and shouldn't be supplied by the client
app.



Your server can then send the message to the phone using your existing SMS
infrastructure or service. When this message is received, Google Play services
broadcasts an intent which contains the text of the message. Here's the code:




class="prettyprint">public class MySMSBroadcastReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
if (SmsRetriever.SMS_RETRIEVED_ACTION.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
Status status = (Status) extras.get(SmsRetriever.EXTRA_STATUS);

switch(status.getStatusCode()) {
case CommonStatusCodes.SUCCESS:
String message = (String) extras.get(SmsRetriever.EXTRA_SMS_MESSAGE);
break;
case CommonStatusCodes.TIMEOUT:
break;
}
}
}
}


In the onReceive of the broadcast receiver you get the extras, and pull the
status from there. If the status indicates that the message was successfully
received, you can pull the message from the extras. From here you can parse out
the verification code and send it back to your server to confirm phone number
ownership.



For more information, check out the full href="https://developers.google.com/identity/sms-retriever/">documentation
and this year's Google I/O
talk
.


Testimonies of Early Adopters



Our early partners who use this API love it. Here are some testimonials from
them:



href="https://www.twilio.com/blog/2017/05/twilio-verification-sdk-android-app-sms-permissions-phone-verification-has-never-been-easier.html">Twilio
observed and blogged that Android SMS Verification has never been easier.



"If you're a developer building mobile apps on Android that use phone
numbers to register and identify user accounts, you should be using Twilio
Verification SDK for Android for the quickest way to solve the problem of
providing a smooth, secure and easy sign-up flow." - Simon Thorpe, Product
Owner at Twilio



href="https://authy.com/blog/authy-for-android-app-is-now-easier-to-use-and-safer-too/">Authy
loved the fact that these APIs work with their existing SMS infrastructure
without requiring many changes.



"Adding Phone Selector + SMS Retriever into Authy 2FA app delivers magical
UX for users while retaining the high security our application requires." --
Serge Kruppa, Head of Authy Engineering



href="https://www.telesign.com/blog/post/telesign-app-verify-now-offers-autosms-mode-with-even-lower-friction-during-android-user-verification/">Telesign
observed better UX, increased security and higher conversion rates with the same
backend framework.



"One significant advantage of this verification mode with lower friction is
that customers might be able to see increased conversion rates for user sign-up
and registration scenarios.



Enhanced security is also a benefit as Google Play Services only provides
access to the SMS message to the targeted application based on the application
hash inside the message." -- Priyesh Jain (Post author)


Read more

10/13/17

Introducing Android Instant Apps SDK 1.1


Jichao Li, Software Engineer; Shobana Ravi, Software Engineer


Since our href="https://android-developers.googleblog.com/2017/05/android-instant-apps-is-open-to-all.html">public
launch at Google I/O, we've been working hard to improve the developer
experience of building instant apps. Today, we're excited to announce
availability of the Android Instant Apps SDK 1.1 with some highly-requested
features such as improved NDK support, configuration APKs for binary size
reduction, and a new API to maintain user's context when they transition from an
instant app to the installed app.


Introducing configuration APKs



For a great instant app experience, app binaries need to be lean and well
structured. That's why we're introducing configuration APKs.



Configuration APKs allow developers to isolate device-specific resources and
native libraries into independent APKs. For an application that uses
configuration APKs, the Android Instant Apps framework will only load the
resources and native libraries relevant to the user's device, thereby reducing
the total size of the instant app on the device.



We currently support configuration APKs for display density, CPU architecture
(ABI), and language. With these, we have seen an average reduction of 10% in the
size of the binaries loaded. Actual savings for a given app depend on the number
of resource files and native libraries that can be configured.



As an example, a user on an ARM device with LDPI screen density and language set
to Chinese would then receive device-agnostic code and resources, and then only
get the configuration APKs that have ARM native libraries, the Chinese language,
and LDPI resources. They would not receive any of the other configuration APKs
such as the x86 libraries, Spanish language strings, or HDPI resources.



Setting up configuration APKs for your app is a simple change to your gradle
setup. Just follow the steps in our href="https://developer.android.com/topic/instant-apps/guides/config-splits.html">public
documentation.


Persistent user context after installation



On Android Oreo, the internal storage of the instant version of the app is
directly available to the installed version of the app. With this release of the
SDK, we are enabling this functionality on older versions of the Android
Framework, including Lollipop, Marshmallow, and Nougat devices.



To extract the internal storage of the instant app, installed apps can now call
href="https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantAppsClient#getInstantAppData()">InstantAppsClient.getInstantAppData()
using the Instant Apps Google Play Services API and get a ZIP file of the
instant app's internal storage.



Check out our href="https://github.com/googlesamples/android-instant-apps">code sample and
href="https://developers.google.com/android/reference/com/google/android/gms/instantapps/InstantAppsClient#getInstantAppData()">documentation
for more details on how to use this API.


Start building your Android Instant App



It's simple to start building your instant app on the latest SDK. Just open the
SDK Manager in Android Studio and update your Instant Apps Development SDK to
1.1.0. We can't wait to see what instant app experiences you build with these
new features.

Read more

10/10/17

The Google Assistant can help control your Android media apps

Posted by Nazmul Idris, Android Devices and Media Developer Advocate


The Google Assistant is available across phones, speakers, Android TV and more.
And it can help users get more done throughout their day—where they need to add
something to a to-do list, turn on the lights, or play a song.



With music specifically, the Assistant has a lot to offer. It can understand
media commands across devices ("play rock music") and supports media controls
(like pause, skip, fast forward, thumbs up). And users can also control Android
media playback through the Google Assistant. For example, you can pause playback
by telling the Google Assistant to "pause playback" without lifting a finger. Or
play music by saying "play rock on Universal Music Player".



In order for the user to control playback in your Android Media app via the
Google Assistant, you can use the href="https://medium.com/google-developers/understanding-mediasession-part-1-3-e4d2725f18e4">MediaSession
APIs to make this happen. We recommend that you use MediaSession over intents as
you craft your app's integration with the Google Assistant.


How to use MediaSession in your app?



Your app must implement a MediaSession that handles a prescribed set of actions
as described in href="https://developer.android.com/guide/topics/media-apps/interacting-with-assistant.html#use_a_media_session">Interacting
with the Google Assistant.



Here are some sample projects that can help you get started using MediaSession
in your media apps:


  1. href="https://github.com/googlesamples/android-MediaBrowserService/">MediaBrowserService
    sample
  2. href="https://github.com/googlesamples/android-UniversalMusicPlayer">Universal
    Music Player sample
  3. Assistant
    Integration with Leanback sample


To learn more about MediaSession here are some good resources:


  1. href="https://medium.com/google-developers/understanding-mediasession-part-1-3-e4d2725f18e4">Understanding
    MediaSession
  2. href="https://developer.android.com/guide/topics/media-apps/working-with-a-media-session.html">Working
    with a MediaSession
  3. href="https://android-developers.googleblog.com/2017/10/video-playback-with-google-assistant-on.html">Video
    Playback with the Google Assistant on Android TV

How does the Google Assistant use MediaSession?



The Google Assistant uses MediaSession in the same way as other external
controllers such as Android Wear do. Each of these controllers cause state
changes inside your app, and there needs to be a way to respond to these
changes. This is where MediaSession comes into play.



By using MediaSession, the Google Assistant can control your app's media
playback, as well as stay synced with its current state.


How do I test my app with MediaSession?



Once you implement MediaSession you will probably want to test how playback can
be controlled outside of your app. The href="https://github.com/googlesamples/android-media-controller">Media
Controller Test tool was created to emulate external control of your media
playback. You can verify that when other apps (like Google Assistant) interact
with your app, that it works as expected.





Read more

10/6/17

Working with Multiple JobServices

Posted by Isai Damier, Software Engineer, Android DA

Working with Multiple JobServices



In its continuous effort to improve user experience, the Android platform has
introduced strict limitations on background services starting in API level 26.
Basically, unless your app is running in the href="https://developer.android.com/about/versions/oreo/background.html#services">foreground,
the system will stop all of your app's background services within minutes.



As a result of these restrictions on background services,
JobScheduler jobs have become the de facto solution for performing
background tasks. For people familiar with services, JobScheduler
is generally straightforward to use: except in a few cases, one of which we
shall explore presently.



Imagine you are building an Android TV app. Since channels are very important to
TV Apps, your app should be able to perform at least five different background
operations on channels: publish a channel, add programs to a channel, send logs
about a channel to your remote server, update a channel's metadata, and delete a
channel. Prior to Android 8.0 (Oreo) each of these five operations could be
implemented within background services. Starting in API 26, however, you must be
judicious in deciding which should be plain old background Services
and which should be JobServices.



In the case of a TV app, of the five operations mentioned above, only channel
publication can be a plain old background service. For some context, channel
publication involves three steps: first the user clicks on a button to start the
process; second the app starts a background operation to create and submit the
publication; and third, the user gets a UI to confirm subscription. So as you
can see, publishing channels requires user interactions and therefore a visible
Activity. Hence, ChannelPublisherService could be an IntentService
that handles the background portion. The reason you should not use a
JobService here is because JobService will introduce a
delay in execution, whereas user interaction usually requires immediate response
from your app.



For the other four operations, however, you should use JobServices;
that's because all of them may execute while your app is in the background. So
respectively, you should have ChannelProgramsJobService,
ChannelLoggerJobService, ChannelMetadataJobService,
and ChannelDeletionJobService.


Avoiding JobId Collisions



Since all the four JobServices above deal with Channel
objects, it should be convenient to use the channelId as the
jobId for each one of them. But because of the way
JobServices are designed in the Android Framework, you can't. The
following is the href="https://developer.android.com/reference/android/app/job/JobInfo.Builder.html#JobInfo.Builder(int,
android.content.ComponentName)">official description of jobId




class="prettyprint">Application-provided id for this job. Subsequent calls to cancel,
or jobs created with the same jobId, will update the pre-existing
job with the same id. This ID must be unique across all clients
of the same uid (not just the same package). You will want to
make sure this is a stable id across app updates, so probably not
based on a resource ID.


What the description is telling you is that even though you are using 4
different Java objects (i.e. -JobServices), you still cannot use the same
channelId as their jobIds. You don't get credit for
class-level namespace.



This indeed is a real problem. You need a stable and scalable way to relate a
channelId to its set of jobIds. The last thing you
want is to have different channels overwriting each other's operations because
of jobId collisions. Were jobId of type String instead
of Integer, the solution would be easy: jobId= "ChannelPrograms" +
channelId
for ChannelProgramsJobService, jobId= "ChannelLogs" +
channelId
for ChannelLoggerJobService, etc. But since
jobId is an Integer and not a String, you have to devise a clever
system for generating reusable jobIds for your jobs. And for that,
you can use something like the following JobIdManager.



JobIdManager is a class that you tweak according to your app's
needs. For this present TV app, the basic idea is to use a single
channelId over all jobs dealing with Channels. To
expedite clarification: let's first look at the code for this sample
JobIdManager class, and then we'll discuss.




class="prettyprint">public class JobIdManager {

public static final int JOB_TYPE_CHANNEL_PROGRAMS = 1;
public static final int JOB_TYPE_CHANNEL_METADATA = 2;
public static final int JOB_TYPE_CHANNEL_DELETION = 3;
public static final int JOB_TYPE_CHANNEL_LOGGER = 4;

public static final int JOB_TYPE_USER_PREFS = 11;
public static final int JOB_TYPE_USER_BEHAVIOR = 21;

@IntDef(value = {
JOB_TYPE_CHANNEL_PROGRAMS,
JOB_TYPE_CHANNEL_METADATA,
JOB_TYPE_CHANNEL_DELETION,
JOB_TYPE_CHANNEL_LOGGER,
JOB_TYPE_USER_PREFS,
JOB_TYPE_USER_BEHAVIOR
})
@Retention(RetentionPolicy.SOURCE)
public @interface JobType {
}

//16-1 for short. Adjust per your needs
private static final int JOB_TYPE_SHIFTS = 15;

public static int getJobId(@JobType int jobType, int objectId) {
if ( 0 < objectId && objectId < (1<< JOB_TYPE_SHIFTS) ) {
return (jobType << JOB_TYPE_SHIFTS) + objectId;
} else {
String err = String.format("objectId %s must be between %s and %s",
objectId,0,(1<<JOB_TYPE_SHIFTS));
throw new IllegalArgumentException(err);
}
}
}


As you can see, JobIdManager simply combines a prefix with a
channelId to get a jobId. This elegant simplicity,
however, is just the tip of the iceberg. Let's consider the assumptions and
caveats beneath.



First insight: you must be able to coerce channelId into a Short,
so that when you combine channelId with a prefix you still end up
with a valid Java Integer. Now of course, strictly speaking, it does not have to
be a Short. As long as your prefix and channelId combine into a
non-overflowing Integer, it will work. But margin is essential to sound
engineering. So unless you truly have no choice, go with a Short coercion. One
way you can do this in practice, for objects with large IDs on your remote
server, is to define a key in your local database or content provider and use
that key to generate your jobIds.



Second insight: your entire app ought to have only one JobIdManager
class. That class should generate jobIds for all your app's jobs:
whether those jobs have to do with Channels, Users, or
Cats and Dogs. The sample JobIdManager
class points this out: not all JOB_TYPEs have to do with
Channel operations. One job type has to do with user prefs and one
with user behavior. The JobIdManager accounts for them all by
assigning a different prefix to each job type.



Third insight: for each -JobService in your app, you must have a
unique and final JOB_TYPE_ prefix. Again, this must be an
exhaustive one-to-one relationship.


Using JobIdManager



The following code snippet from ChannelProgramsJobService
demonstrates how to use a JobIdManager in your project. Whenever
you need to schedule a new job, you generate the jobId using
JobIdManager.getJobId(...).



class="prettyprint">import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.os.PersistableBundle;

public class ChannelProgramsJobService extends JobService {

private static final String CHANNEL_ID = "channelId";
. . .

public static void schedulePeriodicJob(Context context,
final int channelId,
String channelName,
long intervalMillis,
long flexMillis)
{
JobInfo.Builder builder = scheduleJob(context, channelId);
builder.setPeriodic(intervalMillis, flexMillis);

JobScheduler scheduler =
(JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
if (JobScheduler.RESULT_SUCCESS != scheduler.schedule(builder.build())) {
//todo what? log to server as analytics maybe?
Log.d(TAG, "could not schedule program updates for channel " + channelName);
}
}

private static JobInfo.Builder scheduleJob(Context context,final int channelId){
ComponentName componentName =
new ComponentName(context, ChannelProgramsJobService.class);
final int jobId = JobIdManager
.getJobId(JobIdManager.JOB_TYPE_CHANNEL_PROGRAMS, channelId);
PersistableBundle bundle = new PersistableBundle();
bundle.putInt(CHANNEL_ID, channelId);
JobInfo.Builder builder = new JobInfo.Builder(jobId, componentName);
builder.setPersisted(true);
builder.setExtras(bundle);
builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY);
return builder;
}

...
}


Footnote: Thanks to Christopher Tate and Trevor Johns for their invaluable
feedback

Read more
loading...