diff --git a/docs/html/preview/features/data-saver.jd b/docs/html/preview/features/data-saver.jd new file mode 100644 index 0000000000000..4ea47d57caf70 --- /dev/null +++ b/docs/html/preview/features/data-saver.jd @@ -0,0 +1,146 @@ +page.title=N Developer Preview Data Saver +metaDescription=User-enabled data usage optimization. +page.keywords="android N", "data usage", "metered network" +@jd:body + +
+ Over the life of a smartphone, the cost of a cellular data plan can easily + exceed the cost of the device itself. In the N Developer Preview, users can + enable Data Saver in order to use less data, whether roaming, near the end of + the billing cycle, or on a small prepaid data pack. +
+ ++ When a user enables Data Saver in Settings and the device is + on a metered network, the system blocks background data usage and signals + apps to use less data in the foreground wherever possible. Users can + whitelist specific apps to allow background metered data usage even when Data + Saver is turned on. +
+ ++ The N Developer Preview extends the {@link android.net.ConnectivityManager} + API to provide apps a way to retrieve the user’s Data Saver + preferences and monitor preference + changes. It is considered good practice for apps to check whether the + user has enabled Data Saver and make an effort to limit foreground and + background data usage. +
+ ++ In the N Developer Preview, apps can use the {@link + android.net.ConnectivityManager} API to determine what data usage + restrictions are being applied. The {@code getRestrictBackgroundStatus()} + method returns one of the following values: +
+ ++ It is considered good practice to limit data usage whenever the device is + connected to a metered network, even if Data Saver is disabled or the app + is whitelisted. The following sample code uses {@link + android.net.ConnectivityManager#isActiveNetworkMetered + ConnectivityManager.isActiveNetworkMetered()} and {@code + ConnectivityManager.getRestrictBackgroundStatus()} to determine how much data + the app should use: +
+ +
+ConnectivityManager connMgr = (ConnectivityManager)
+ getSystemService(Context.CONNECTIVITY_SERVICE);
+// Checks if the device is on a metered network
+if (connMgr.isActiveNetworkMetered()) {
+ // Checks user’s Data Saver settings.
+ switch (connMgr.getRestrictBackgroundStatus) {
+ case RESTRICT_BACKGROUND_STATUS_ENABLED:
+ // Background data usage is blocked for this app. Wherever possible,
+ // the app should also use less data in the foreground.
+
+ case RESTRICT_BACKGROUND_STATUS_WHITELISTED:
+ // The app is whitelisted. Wherever possible,
+ // the app should use less data in the foreground and background.
+
+ case RESTRICT_BACKGROUND_STATUS_DISABLED:
+ // Data Saver is disabled. Since the device is connected to a
+ // metered network, the app should use less data wherever possible.
+ }
+} else {
+ // The device is not on a metered network.
+ // Use data as required to perform syncs, downloads, and updates.
+}
+
+
++ Apps can monitor changes to Data Saver preferences by creating a {@link + android.content.BroadcastReceiver} to listen for {@code + ConnectivityManager.ACTION_RESTRICT_BACKGROUND_CHANGED} ({@code + "android.net.conn.RESTRICT_BACKGROUND_CHANGED"}) and dynamically registering + the receiver with {@link android.content.Context#registerReceiver + Context.registerReceiver()}. When an app receives this broadcast, it should + check if the new Data Saver preferences affect its + permissions by calling {@code + ConnectivityManager.getRestrictBackgroundStatus()}. +
+ ++ Note: The system only sends this broadcast to apps that + dynamically register for them with {@link + android.content.Context#registerReceiver Context.registerReceiver()}. Apps + that register to receive this broadcast in their manifest will not receive + them. +
\ No newline at end of file