Google Play Services 8.4 SDK is available

Posted by Laurence Moroney, Developer Advocate



We’re delighted to announce the availability of Google Play services 8.4. There’s a lot of new information to share with you about what’s available to you in this release.







Custom Email App Invites



App Invites is a technology that enables your users to share apps with people they know. In Google Play services 8.4 we’ve updated this to make it easier for them to share via email. Before this you could create a custom email that contained user defined text and an image, but now we’re allowing you to add content from the app directly into the message. It allows you to fully define the email body using HTML, and set the email subject line. So, for example, if you have a favorite cooking app that you want to share with your friends, your invite to use the app can include a favorite recipe from the app. They get the immediate benefit of being able to access the desired content, giving them a more informed choice about whether or not they decide to install the app to get richer and more content. Check out the App Invites sample on GitHub here.



Predicting User spend and churn in games



The Play Games Analytics developer experience is designed to enable game developers to better understand, manage, and optimize game experiences throughout the player lifecycle. With this in mind, we’ve extended the Player Stats API to help you better understand your players behavior, and based on this, entice them to stay in your game.




The churn prediction method will return data on the probability that the player will churn, i.e., stop playing the game. You can create content in response to this to entice them to stay in your game.



Additionally, the spend prediction method will return the probability that the player will spend something in the game. It’s up to you how to handle this data, but -- for example -- if there’s a low probability that the player will spend something, you could provide discounted in-app purchases or show ads.



Fused Location Provider Updates



The Fused Location Provider (FLP) in Google Play services provides location to your apps using a number of sensors, including GPS, WiFi and Cell Towers.



When desiring to save battery power, and using coarse updates, the FLP doesn’t use Global Positioning Services (GPS), and instead uses WiFi and Cell tower signals. In Google Play services 8.4, we have greatly improved how the FLP detects location from cell towers. Prior to this, we would get the location information relative to only the primary cell tower. Now, the FLP takes the primary tower and other towers nearby to provide a more accurate location. We’ve also improved location detection from WiFi access points, particularly in areas where GPS is not available -- such as indoors.



Maps API Improvements



Have you ever wished you could easily handle a tap on a suburb without having to add another layer on the map to intercept the taps? We’ve added an onClickListener for polygons, so you can easily add transparent polygons and intercept the taps directly. We’ve also added on click listeners to polylines and ground overlays.



Here’s how you can use a listener to detect a click on a polygon:


 map.setOnPolygonClickListener(new GoogleMap.OnPolygonClickListener() {  
@Override
public void onPolygonClick(Polygon polygon) {
...
}
});


Info windows now also offer an OnInfoWindowCloseListener and an OnInfoWindowLongClickListener. The on close listener is particularly useful if you wish to zoom back out on the map after the user has looked at the detail associated with a particular marker.


 mMap.setOnInfoWindowCloseListener(new GoogleMap.OnInfoWindowCloseListener() {...});  

 mMap.setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() {...});  


For more details, and an example that uses these, see the ApiDemos sample on GitHub and check out the historical changes to this sample, so you can see how the new APIs work. Also see the Release Notes.



Support for Aztec bar codes



In Google Play services 7.8, we launched Vision APIs that supported face and barcode detection. One bar code format we didn’t support was Aztec bar codes, so with Google Play services 8.4 we’ve now added support for these.



Applications using BarcodeDetector in its default configuration (no barcode format restrictions) will automatically start decoding AZTEC codes.



Background Beacon Scanning



With Google Play services 8.4, the Nearby Messages API now supports background scanning for Eddystone, the open beacon format from Google. With this update, your app can be woken up when a BLE beacon is sighted. Back in July, Google Play Services 7.8 introduced the Nearby Messages API with a simple publish-subscribe interface. In the case of beacons, developers publish content by adding attachments to beacon records using Proximity Beacon API. These attachments are served back to your app when Nearby sights a beacon of interest.




New methods that we’ve added include a subscribe method for background beacon subscriptions where BLE scans are triggered at screen-on events; an associated unsubscribe event; and the ability to handle intents that you get when the Nearby API calls back during a background subscription.



Fitness Platform HistoryApi Improvements



We now support consistent step counts across the Google Fit app, other fitness apps and Android Wear watch faces with the HistoryApi.readDailyTotal() method. Please see the following documentation for more detail:
https://developers.google.com/fit/android/history#read_daily_total_data?utm_campaign=play services_series_launch_121815&utm_source=anddev&utm_medium=blog



We also have a new HistoryApi.updateData() method. This method allows you to update data in one API call without having to delete and insert with two calls.



Place Picker Autocomplete Widget



Today we are announcing the mobile autocomplete widget, the latest addition to our existing set of programmatic autocomplete features on Android and iOS, as well as the addition of Autocomplete to our place picker widget. Autocomplete functionality assists users by automatically completing the name and address of a place as they type. Widgets make it even easier for developers to add autocomplete functionality to their application with just a small amount of code. Learn more about this at this blog post.


















The Learning Continues! New lessons for Advanced Android course

Posted by Joanna Smith, Developer Advocate



Magic moments happen when your app does something very useful with minimal effort from your users -- like figuring out their location for them automatically. The new Places lesson in the Advanced Android App Development course teaches you how to add a Place Picker to your app so that users can pick a nearby location without having to type anything.



The Advanced Android App Development course, built by Udacity in conjunction with Google, is a follow-up course to Developing Android apps. The advanced course is for Android Developers who are ready to learn how to polish, productionize and publish their app, and even distribute it through Google Play.







Updates to the course also include an explanation of the new GCM Receiver, as well as an entirely new lesson on publishing your app, which explains how to build and sign an APK so you you can distribute your app on Google Play.




After all, why build an app if you can’t get it to your users?


Get started now, because it's going to be awesome!

Invitation: Your Ultimate 31-Course Holiday Banquet

Posted by Shanea King-Roberson, Program Manager



The Holidays. Food for the body. Food for the mind. Google and Udacity offer you 31 courses that will make your mouth water and your mind dance. Savor one or several of our 31 self-paced online training courses to indulge your curiosity, expand your knowledge, and hone new skills. Choose from Android, Web, Entrepreneurship, or Cloud and Backend tracks. Are you ready?





Android



More and more people around the world are embracing mobile at an increasing pace, whether on their phones, in their cars, at home, and around their wrists. Learn to build apps for them!






Web



Refine your web development skills for mobile. Create fast, fluid user experiences. Deploy for all desktop and mobile devices. Streamline checkout and payment. Learn how to build beautiful, performant, responsive applications for the world's largest platform.






Cloud and Backend



Does your app need to support more users? (Congratulations!) Do you want to move data handling for an existing app from the device to the cloud? Learn how to take advantage of public cloud infrastructure to support millions of users and terabytes of data.






Entrepreneurship



Start the year with a new start up. That says it all. Take these courses to learn how to do it successfully.





And that’s it. 31 courses that will catapult your skills and make 2016 your best year yet!
Happy Holidays!


Silent Night with Night Light

Any time is a good time to read, but at night is perhaps the best. What better way to drift off to sleep than with a great book? Our readers agree. Looking at reading time across the world, we see that activity peaks between 8:00 pm and 10:00 pm local time. But we also know looking at a bright screen before bed can be hard on your eyes. Cue the announcement!

Today we’re introducing Night Light, a new feature that makes night time reading more enjoyable and easier on the eyes. When turned on, Night Light gradually filters blue light from your screen, replacing it with a warm, amber light as the sun sets. Night Light automatically adapts to the amount of natural sunlight outside based on the time of day, giving you just the right temperature and brightness. The color adjustment is more comfortable on your eyes and greatly improves low-light night reading.


Night Light is rolling out to Android and iOS readers now, and turning it on is easy. To activate Night Light on your phone or tablet, update your Google Play Books app to the latest version through Google Play or the App Store. Then open a book and turn on the Night Light mode option (you’ll see a pop up in the app). After that, Night Light will always adjust to the perfect setting. We hope Night Light will help you drift off into a peaceful slumber once you finish just one more chapter.

Posted by Greg Hartrell, Senior Product Manager, Google Play Books

Android Wear: Dress things up with new designer watch faces

What makes a watch worth wearing? It should be beautiful and useful. Save you time and express your style. Like mechanical watches, Android Wear watches come in countless sizes, styles, and brands. And the different ways to wear what you want keep growing—just last month, Swiss watchmaker TAG Heuer and fashion brand Fossil launched their first watches powered by Android Wear.

But a watch’s physical design isn’t the only way to express your style with Android Wear. You can also choose from thousands of inspiring, useful, and downloadable watch faces. Today, we’re sharing new watch faces from nine iconic fashion brands.

  • Ted Baker: Reveal your sophisticated side with ten gorgeous designs. 
  • Melissa Joy Manning: Rock a different birthstone for every month of the year. 
  • Vivienne Tam: Watch Opera Girl twirl, take a selfie, and more.
  • Nicole Miller: Stay on track and in style with Nicole Miller’s pop art.
  • Y-3: Sport the styles of Yohji Yamamoto, inspired by the beauty of human movement. 
  • Mango: Add instant chic to any outfit with this ready-to-wear watch face.
  • Zoe Jordan: Free your time of clutter with the clean lines of modern design.
  • Harajuku Kawaii!: Express your playful side with this adorable and vibrant watch face. 
  • ASICS: Motivate yourself to stay active with the help of your fitness buddy.

Android phone owners can download these watch faces today. And iPhone owners can find these unique designs in their Android Wear mobile app in the coming days. ‘Tis the season for festivities and fun! Pick your fashion favorites to match your outfit, mood, or occasion. 



Posted by Kaitlyn Hurst, Product Marketing Manager, Android Wear

Tap. Pay. Next.

Since our launch this Fall, we've seen millions of people set up Android Pay, and the vast majority of them are using tap and pay with their Android devices for the first time. There are now over 1 million locations across the United States that already accept tap and pay, with more being added every day. In short, the response from customers and merchants has been tremendous.

Now we’re ready for the next step: We're working to bring Android Pay's simplicity and security to purchases within apps, and to people in more countries around the world.

Android Pay in apps
Starting today, you’ll be able to use Android Pay to speed through mobile checkout within many of your favorite Android apps in the US.



No more pulling out your credit card while on-the-go. No more errors thanks to clumsy thumbs. Just tap the Android Pay button in the app, confirm your information, and you’re done! And just like your purchases in stores, Android Pay never shares your card details with merchants.

Meet our growing collection of apps
In the next few months, you’ll see more and more of your favorite apps adding Android Pay to help you speed through mobile checkout. For a limited time, you’ll also get special savings by using Android Pay in select apps—from $20 off on OpenTable* dining, $10 off your Lyft ride*, $10 off DoorDash* to 30% off Vinted*—there’s something for everyone. Visit our collection to view all the offers.



Developers: want to add Android Pay to your app? You can visit the Android Pay API developer site to learn how to accept Android Pay for the purchase of physical goods and services. We’ve worked with leading payment providers to make accepting Android Pay a breeze.

Android Pay in more countries
We're also taking the first step to bring the convenience of Android Pay to Android users across the globe. In the first half of 2016, Android Pay will arrive in Australia. We’re working closely with many of Australia’s major financial institutions—including ANZ, Westpac and many other banks—with the aim of bringing Android Pay to their MasterCard and Visa card holders. You will be able to use Android Pay wherever NFC payments are accepted in the country, including merchants such as 7-Eleven, McDonald's and Telstra.

And Australia is just the start. We’ll be adding more countries throughout 2016. This was a big year for Android Pay, and we're excited about what's to come.

Posted by Pali Bhat, Director of Product Management, Android Pay 

* Subject to merchant terms and conditions.

Leveraging product flavors in Android Studio for hermetic testing

Posted by Jose Alcérreca, Developer Programs Engineer and Wojtek Kaliciński, Developer Advocate







During our recent talk at Android Dev Summit, we discuss the state of testing on Android on the example of a simple Notes application that we created as part of our testing codelab. In one section of the talk, we discuss the problem of test flakiness and introduce a simple solution for setting up a hermetic testing environment.



Combatting flaky tests



UI tests with frameworks like Espresso or UI Automator can easily get flaky if the application has external dependencies that can sometimes fail or take long to respond. In short, flaky tests are tests that are not reliable (they can pass or fail randomly) which defeats the whole purpose of having tests in the first place.



A common solution to this problem is hermetic testing or, in other words, making sure that your tests are isolated from dependencies. Using fake implementations or fake servers that just return predefined data is a common way of dealing with this problem. Here are some good examples:




  • Network calls can be made via a fake API client or fake server that immediately returns data from files stored on disk instead of hitting the network. This bypasses the network's latency and flakiness as well as any errors originating on the real server.

  • Interactions with low-level framework APIs (especially those for accessing hardware, like camera or storage) can be passed through an intermediate interface. A fake implementation of this interface could return immediately, providing a reference to preloaded data, such as an image, without relying on the hardware.

  • Any sensors can be replaced with fakes too: GPS, microphone, accelerometer etc., giving you a chance to test on data that would be difficult to provide for the test in real life, like a preset location or a set of inputs simulating a gesture.



Dependency Injection (DI) is a software design pattern that facilitates testing, reusing modules and making them interchangeable. DI frameworks can help you deal with the boilerplate associated with this pattern but it can take a considerable amount of time to set them up and understand how they work. Before you are ready to commit to one of those frameworks for your app, you might want to explore an easier way, especially if your project requirements are simple.



Managing dependencies with product flavors



Product flavors is a powerful feature of Android Studio and our Android Gradle plugin that lets you swap Java classes at compile time and doesn't require additional libraries. Some typical examples of flavor dimensions are:





  • free/paid flavors to generate two different APKs that will be released on your distribution channels

  • stable/experimental to keep experiments in a different source set and generate beta versions quickly



We can leverage the same mechanism to create two separate versions of our app to help with hermetic testing:



  • prod - uses real implementation of services and components, using real data and resources

  • mock - for a version that contains fake implementations of dependencies that are hard to test



The procedure is very simple:



  1. Create the flavors in your app/build.gradle file.
     android {  
    productFlavors {
    mock {
    applicationIdSuffix = ".mock"
    }
    prod
    }
    }

  2. Create two directories: app/src/prod and app/src/mock

  3. Create the class that you want to use for production code in the prod/java folder or move it from main/java. Make sure the main/java folder does not contain this class.
  4. Create the same class (with the exact same class and file name) in the mock/java folder, but providing a different (fake) implementation that will be used for tests.
  5. In the Build Variants window in Android Studio, choose the variant that you want to install or run tests against. A variant is the combination of a flavor and a build type.


Note: In gradle, the task names change when you add flavors. Instead of installDebug, you will now have to choose installProdDebug or installMockDebug.



Running your tests



With the prod and mock flavors configured and your mock implementation in place, you can now use the following gradle tasks to choose how your tests should run:




  • connectedMockDebugAndroidTest will merge the androidTest and androidTestMock directories and run every test found in the resulting source set. As these tests are run in a hermetic way, they will be faster and less flaky. This is ideal for a pre-submit check.

  • connectedProdDebugAndroidTest will use the real APIs and sensors so they might fail from time to time. If you have a Continuous Integration system, this task could be executed every night or used manually as a acceptance end-to-end test. Note that this task will run the tests in androidTest even if androidTestProd doesn't exist.



You can refer to our Android Testing Codelab to see how we used this method to provide different Injection class implementations, the one in prod providing real data and the other (mock) serving fake dependencies that use fake data for isolated test execution.



When you’re happy with your hermetic setup, you might want to give more flexibility to your build process and add even more dimensions to be able to interchange different components in your app. While the method discussed above is suitable for simple projects, for more complex situations it would be much better to invest some time to learn about and add a Dependency Injection framework to your project.