简体   繁体   English

Android应用程序能否将其他应用程序限制为仅WiFi(无root用户)?

[英]Is it possible for an Android app to restrict other apps to WiFi only (without root)?

I was wondering if it was possible to make an android app (that does not require root) that could enable and disable the use of mobile data for other apps? 我想知道是否有可能制作一个可以启用和禁用其他应用程序使用移动数据的android应用程序(不需要root)? I know there's a function to toggle background services per app inside the native Android settings, so maybe there's some public methods for me to do so with my own app. 我知道有一个功能可以在本机Android设置内切换每个应用程序的后台服务,所以也许我可以使用一些公共方法来使用自己的应用程序。

Basically, I want my app to control whether other apps could access data via mobile data or WiFi only. 基本上,我希望我的应用控制其他应用是否只能通过移动数据或WiFi访问数据。

Pointing me to the right direction would be greatly appreciated as well. 为我指出正确的方向也将不胜感激。

Theoretically, yes. 从理论上讲,是的。

See: https://github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/cmds/svc/src/com/android/commands/svc/DataCommand.java 参见: https : //github.com/android/platform_frameworks_base/blob/dbc51de44fe4f9a7f81528204250de32ec405d39/cmds/svc/src/com/android/commands/svc/DataCommand.java

This is the svc tool that can be launched via adb shell . 这是可以通过adb shell启动的svc工具。 It did error out with code 137 for me (unrooted Nexus 5), though. 不过,它确实为我提供了错误代码137(未扎根的Nexus 5)。 But from the code you see how this should theoretically work. 但是从代码中您将看到理论上该如何工作。

You retrieve the TelephonyManager and enableDataConnectivity , which is, of course, a hidden API (see: https://github.com/android/platform_frameworks_base/blob/6b8a3a52acf1c2722551f1ea1ce47831f87939cd/telephony/java/com/android/internal/telephony/ITelephony.aidl ). 您将获取TelephonyManagerenableDataConnectivity ,这当然是一个隐藏的API(请参阅: https : //github.com/android/platform_frameworks_base/blob/6b8a3a52acf1c2722551f1ea1ce47831f87939cd/telephony/java/com/android/internal/telephony/ITelephony.aidl )。 Accessing hidden APIs is possible by recompiling the android.jar that you build against, or by using reflection (see: How do I build the Android SDK with hidden and internal APIs available? ). 通过重新编译生成的android.jar或使用反射,可以访问隐藏的API(请参阅: 如何使用可用的隐藏和内部API构建Android SDK? )。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM