How can I **disable** the Internet? - android

I am developing an application. In which, I want to disable the using Internet for some time, especially if he has homework. How can I disable the Internet ?

To enable/disable data connection programatically check this post
To disable / enable wi-fi refer this tutorial

You can set the "mobile data" and "wifi state" whithin your application as long as you have the right permissions.
Also, you can register system wide BroadcastListener to detect when the device is connected to the internet, and do whatever you consider needs to be done.

There are ways to do this using Airplane mode, or via system hooks but the user will still retain the power to connect back. If you disconnect it again, he can disable/remove your app.
Is there an absolute way to restrict the user? I don't believe so. For security reasons alone, Providing this ability to third party applications would be very dangerous.

Related

android - Force my app to use WiFi only

I'm a PHP developer, but I'm now finishing Android App that different developer started.
One of the requirements is to make it possible to disallow mobile connection. For that I already created checkbox preference on settings page I got.
But I can't find correct way to globaly disallow my app to use mobile connection for data transactions. I don't need to disable connection, I just need to forbid my app to use it and use only WiFi. I got too much places, where connection is done and no time to refactor it.
TL;DR
I need to globally forbid my app to use mobile connection without disabling connection itself.
Just can say one thing is that Android allows to turn on/off WiFi manually only because of security.

Prevent user from turning OFF WiFi using code - Android

I'm designing an app which uses wifi for certain purposes. I want to prevent the user from turning the wifi radio off from the wifi settings of the device while my application is running and the device connected to my wifi network. Is there a chance this can be done? I read in WifiManager.WifiLock and they say this: "Note that WifiLocks cannot override the user-level "Wi-Fi Enabled" setting, nor Airplane Mode. They simply keep the radio from turning off when Wi-Fi is already on but the device is idle." Can it be done somehow??
You cannot prevent the user from turning off the wifi from your code. Even if you find out an evil way to do it , you should not try to do it. If I find out any app in my phone does evil things like these, I will just remove the app. I am sure most people are just like me.
If you really want to do it for some reason , perhaps you could tell us what the scenario is and we might be able to help you with a different solution you havent thought about

Restrict Android Device Wifi Connection‏

How to force android to connect specifically defined wireless network
Is it possible?
User should able to connect defined work wi-fi or wifis,
but should not access any other networks like home.
Firstly for what you want to do that?For your application or the device?
If it's your application you can do restrictions about connection type and network etc.
But if you are talking about the device you cant achieve something like that unless you have the control of the whole system which is not possible.
One option would be to create an app or service that would pick up the:
NETWORK_STATE_CHANGED_ACTION Intent
And then in turn use the
WifiManager.getConnectionInfo()
to check whether this is a legitimate network, if not then just disconnect and notify the user.

Which is better w.r.t battery usage ? Having bluetooth always on OR switching it on/off intermittently ?

I'm writing a app that requires bluetooth. I periodically check if I need to synchronize some data.
W.r.t battery usage which is better ?
Having bluetooth always on and using it when needed for communication.
OR
Switching it on when needed and switching it off.
I believe you shouldn't force the BT state on the users, for whatever reasons they might prefer to keep it on or off. The only thing you application can do is to ask the user to switch BT on whenever you need it (using intent BluetoothAdapter.ACTION_REQUEST_ENABLE), and if you ask every 30mn or so it is rapidly going to be annoying.
Remember the enable() method in BluetoothAdapter should not be used without user consent (from sdk reference):
Bluetooth should never be enabled without direct user consent. If you want to turn on Bluetooth in order to create a wireless connection, you should use the ACTION_REQUEST_ENABLE Intent, which will raise a dialog that requests user permission to turn on Bluetooth. The enable() method is provided only for applications that include a user interface for changing system settings, such as a "power manager" app.
I think it really depends on the time interval between your checks. If the checks are at large intervals, it's better to switch on/off, otherwise, if they are often it probably won't make much difference to keep in on.
Add a button to "turn on bluetooth and sync", when it's over give the user feedback and then request to turn it off.

Android service that only allows WiFi Internet connectivity for installed apps?

is there a way I can force Internet access for installed apps
to only go through wifi, ie prevent any data transfer via the radio/3G
interface?
I'm looking for a solution that wouldn't require a jailbroken phone,
so I guess fooling around with iptables might be out of the question.
Please let me know, thanks.
I suppose you could use the solution for this question:
Android: Stop/Start service depending on WiFi state?
You'll need to modify it a bit, but that'll let you know when WiFi is activated and deactivated. I'm not sure what the purpose of your application is, but I certainly wouldn't recommend doing it.

Categories

Resources