I'm developing an app in which user can enable/disable mobile network on button click. I googled regarding this, but I get the solution of Airplane mode only. In airplane mode, WI-FI and Bluetooth are also disabled. I don't want them to disable by using airplane mode concept. I want only mobile network to be disabled. What are the possible way to implement it pro-grammatically?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
Use below code for Disable/Enable Mobile Network..
you must add below permission in
menifest.xml
If you want Disable whole network then you can do Disable/Enable
AirplaneMode
If you have root-permission you can use this method to disable mobile network:
If you want to enable mobile network, just replace disable with enable.
Mobile data is a Global setting (formerly Secure setting). According to the documentation
The reason to not allow apps to change this setting without a direct user involvement is to protect users from paying unexpected bills coming after malicious app "decides" to switch mobile data on while in roaming or for users without data flat rate.
Any existing solution which allows to change this setting uses reflection and exploits a security hole in Android system which might still exist on some phones. In any case, Android team is very serious about such holes and they fix security issues as soon as they find them. Thus any working today's solution will stop working tomorrow. I would not rely on them.
If you want to help users to switch mobile data faster out of your application, you should rather popup a system setting dialog where users can turn mobile data on or off by themselves. In Android 4.0 and higher you can do this like following.
If you still decide to have a "direct switch", you can use one of reflection-based solutions posted in this thread. But be aware, they won't work on every phone and can stop working after every new system update.