Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect mobile hotspot feature availability in Android programmatically?

I hope title itself says what my question is...

For example, We can check the Wifi availability with PackageManager like

packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);

Similarly is there any way to detect Mobile hotspot feature availability in Android programmatically?

Thanks.

like image 769
RuntimeException Avatar asked Aug 25 '15 12:08

RuntimeException


2 Answers

i went through google documentation and found that if wifi P2P is supported by device then its obvious it suports wifi hotspot

to check Wi-Fi Direct/ wifi P2P by device then check this way

PackageManager m = getPackageManager();
     if (!m.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)) {
            // This device does support wifi P2P
        }

but google says its better to check for this support in your broadcast receiver itself this way

@Override
public void onReceive(Context context, Intent intent) {
    ...
    String action = intent.getAction();
    if (WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION.equals(action)) {
        int state = intent.getIntExtra(WifiP2pManager.EXTRA_WIFI_STATE, -1);
        if (state == WifiP2pManager.WIFI_P2P_STATE_ENABLED) {
            // Wifi P2P is enabled
        } else {
            // Wi-Fi P2P is not enabled
        }
    }
    ...
}

check google documentation for same

like image 72
Jolson Da Costa Avatar answered Sep 21 '22 05:09

Jolson Da Costa


The is maybe the first step to the solution.

See: Android Wifi Hotspot Manager Class

like image 44
JuergenKie Avatar answered Sep 20 '22 05:09

JuergenKie