[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[],[],null,["# Add 5G capabilities to your app\n\nAndroid 11 adds functionality to support 5G in your apps. This\ntopic covers the functionality and gives you an overview of how adding\n5G-specific functionality to your app can improve the user experience.\n\nBuild for 5G\n------------\n\nWhen deciding how to engage with 5G, think about what types of experiences you\nare trying to build. Some ways that 5G can enhance your app include:\n\n- Automatically make current experiences faster and better because of the speed and latency improvements of 5G.\n- Up-level the user experience, such as by showing 4k video or downloading higher-resolution game assets.\n- After confirming that the increased data usage won't cost the user, include experiences normally only provided over Wi-Fi, such as proactively download content typically reserved for unmetered Wi-Fi.\n- Provide experiences unique to 5G that work only with high speeds and low latency.\n\n5G functionality\n----------------\n\nAndroid 11 introduces the following functionality changes and\nenhancements:\n\n- [Meteredness](#meteredness)\n- [5G detection](#detection)\n- [Bandwidth estimation](#estimator)\n\n### Check meteredness\n\nThe\n[`NET_CAPABILITY_TEMPORARILY_NOT_METERED`](/reference/android/net/NetworkCapabilities#NET_CAPABILITY_TEMPORARILY_NOT_METERED)\nis a capability added in Android 11 that tells you if the\nnetwork you are using is unmetered based on information provided by cellular\ncarriers.\n\nThe new flag is used alongside\n[`NET_CAPABILITY_NOT_METERED`](/reference/android/net/NetworkCapabilities#NET_CAPABILITY_NOT_METERED).\nThe existing flag indicates if a network is *always* unmetered, and applies to\nboth Wi-Fi and cellular connections.\n\nThe difference between the two flags is\n`NET_CAPABILITY_TEMPORARILY_NOT_METERED` may change without the network type\nchanging. Apps that target Android 11 can use the\n`NET_CAPABILITY_TEMPORARILY_NOT_METERED` flag. On devices running on Android 9\nand lower, the OS will not report on the flag. For apps running on Android 10,\nthis flag may be available, depending on the device it is running on.\n\nOnce you've determined that the current network is temporarily or permanently\nunmetered, you can display higher-resolution content (such as 4k video), upload\nlogs, back up files, and proactively download content.\n\nThe following sections cover the steps to add meteredness-checking to your app.\n\n#### Register a network callback\n\nRegister for a network callback using\n[`ConnectivityManager.registerDefaultNetworkCallback()`](/reference/android/net/ConnectivityManager#registerDefaultNetworkCallback(android.net.ConnectivityManager.NetworkCallback))\nto hear when `NetworkCapabilities` change. You can detect changes to\n`NetworkCapabilities` by overriding the\n[`onCapabilitiesChanged()`](/reference/android/net/ConnectivityManager.NetworkCallback#onCapabilitiesChanged(android.net.Network,%20android.net.NetworkCapabilities))\nmethod in your `NetworkCallback`.\n\n`registerDefaultNetworkCallback()` causes the registered callback to trigger\nimmediately when registered, giving the app info about the current state. Future\ncallbacks are critical for the apps to take appropriate action when the state is\nchanging from unmetered to metered or the other way around.\n\n#### Check for meteredness\n\nUse the `NetworkCapabilites` object that you receive in a network callback to\ncheck the output of the following code: \n\n### Kotlin\n\n```kotlin\nNetworkCapabilities.hasCapability(NET_CAPABILITY_NOT_METERED) ||\n NetworkCapabilities.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED)\n```\n\n### Java\n\n```java\nNetworkCapabilities.hasCapability(NET_CAPABILITY_NOT_METERED) ||\n NetworkCapabilities.hasCapability(NET_CAPABILITY_TEMPORARILY_NOT_METERED)\n```\n\nIf the value is true, then you can treat the network as unmetered.\n\n#### Additional considerations\n\nWhen working with this functionality, keep the following in mind:\n\n- Using the `NET_CAPABILITY_TEMPORARILY_NOT_METERED` flag requires that you\n compiled your app against the Android 11 SDK.\n\n- The `NET_CAPABILITY_NOT_METERED` capability is permanent on a network. A\n network with this capability will disconnect automatically if it loses the\n capability (becomes metered).\n\n- In contrast, `NET_CAPABILITY_TEMPORARILY_NOT_METERED` may change on a network\n *without disconnecting* . Therefore, apps must listen for the\n `onCapabilitiesChanged()` callback to handle when the network returns to its\n metered status (loses the `NET_CAPABILITY_TEMPORARILY_NOT_METERED`\n capability).\n\n- A network can't have both `NET_CAPABILITY_NOT_METERED` and\n `NET_CAPABILITY_TEMPORARILY_NOT_METERED` at the same time.\n\n### 5G detection\n\nStarting in Android 11, you can detect if the device is connected\nto a 5G network using a callback-based API call. You can check for whether the\nconnection is a 5G NR (standalone) or NSA (nonstandalone) network.\n| **Note:** While you can detect if you are connected to a 5G network, you cannot assume meteredness, connection speed, nor bandwidth from this signal.\n\nSome uses for this API call may include:\n\n- Displaying 5G branding in your app to highlight that you're offering a unique\n 5G experience.\n\n- Activating a unique 5G experience in the app only when on a 5G network. You\n should pair this status check with [checking for meteredness](#meteredness).\n\n- Keeping track of 5G connections for analytics purposes.\n\nTo test 5G detection without a 5G device, you can use features [added to the\nAndroid SDK emulator](/about/versions/11/behavior-changes-all#emulator-5g).\n\n#### Detect 5G\n\nCall\n[`TelephonyManager.listen()`](/reference/android/telephony/TelephonyManager#listen(android.telephony.PhoneStateListener,%20int)),\npassing in\n[`LISTEN_DISPLAY_INFO_CHANGED`](/reference/android/telephony/PhoneStateListener#LISTEN_DISPLAY_INFO_CHANGED),\nto determine if the user has a 5G network connection. Override the\n[`onDisplayInfoChanged()`](/reference/android/telephony/PhoneStateListener#onDisplayInfoChanged(android.telephony.TelephonyDisplayInfo))\nmethod to determine the type of network used for display purposes. One exception\nis that if the carrier opts to show *5G* as the RAT for their mmWave network,\n`OVERRIDE_NETWORK_TYPE_NR_NSA` is returned.\n\nThe following table shows the networks that correspond to the values:\n\n| **Return type** | **Network** |\n|--------------------------------------------------------------------------------------------------------------------------------------|------------------------------------|\n| [`OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO`](/reference/android/telephony/TelephonyDisplayInfo#OVERRIDE_NETWORK_TYPE_LTE_ADVANCED_PRO) | Advanced pro LTE (5Ge) |\n| [`OVERRIDE_NETWORK_TYPE_NR_NSA`](/reference/android/telephony/TelephonyDisplayInfo#OVERRIDE_NETWORK_TYPE_NR_NSA) | NR (5G) for 5G Sub-6 networks |\n| [`OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE`](/reference/android/telephony/TelephonyDisplayInfo#OVERRIDE_NETWORK_TYPE_NR_NSA_MMWAVE) | (5G+/5G UW) for 5G mmWave networks |\n\n| **Note:** Your app must have the [`READ_PHONE_STATE`](/reference/android/Manifest.permission#READ_PHONE_STATE) permission in order to use this API.\n\n### Bandwidth estimation\n\nBandwidth estimation uses the `NetworkCapabilities` object that you work with\nwhen determining meteredness. You can get bandwidth estimates using that object.\n\nThe reliability and accuracy of the bandwidth estimation methods\n[`getLinkDownstreamBandwidthKbps()`](/reference/android/net/NetworkCapabilities#getLinkDownstreamBandwidthKbps())\nand\n[`getLinkUpstreamBandwidthKbps()`](/reference/android/net/NetworkCapabilities#getLinkUpstreamBandwidthKbps())\nimprove in Android 11 due to upgrades to framework support and\nplatform/modem bug fixes to accommodate 5G.\n\nBandwidth defaults provide guidance on app start-up only. This should help you\nwith the \"start-up on idle\" scenario. Your app should measure what it sees\nonce your users have started engaging with the app and adjust its streaming\nbehavior dynamically. For example, you may choose the resolution of video to\nprovide based on the bandwidth estimation at startup. Continue checking the\nestimates as your users use the app; as their connection type and\nstrength changes, adjust your app's behavior accordingly.\n| **Note:** Bandwidth estimates, alone, cannot tell you if the user is on 5G or not. To determine that, see [5G detection](#detection)."]]