Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何以编程方式限制Android中的背景数据?_Android_Performance_Android Studio - Fatal编程技术网

如何以编程方式限制Android中的背景数据?

如何以编程方式限制Android中的背景数据?,android,performance,android-studio,Android,Performance,Android Studio,我正在尝试制作一个应用程序来阻止单个应用程序使用数据。我到处检查,什么也没找到 我已经试过了,但它是为了显示数据使用情况,而不是如何限制背景数据 ConnectivityManager connMgr = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); // Checks if the device is on a metered network if (connMgr.isActiveN

我正在尝试制作一个应用程序来阻止单个应用程序使用数据。我到处检查,什么也没找到

我已经试过了,但它是为了显示数据使用情况,而不是如何限制背景数据

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.
}

你不能通过编程来完成。任何应用程序都不能禁用或启用数据使用,这将是一个安全问题


您唯一能做的就是在“系统设置”中打开请求的页面,提示用户这样做。

在android设置中,它显示的内容将限制后台数据。。。我想当我为某个特定的应用程序切换时,该应用程序不应该从wifi和移动应用程序中获取互联网背景。这是可能的还是不可能的。@TapanPatro,这是不可能的,也不应该是可能的。如何。。在iOS中,此选项存在。。设置-->移动数据-->和开关??为什么有这么多的反对票?这个问题是相关的。