mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Remove hotspot code for API<26 from WifiHotspotManager.java
Remove the code for turning on hotspot programmatically for API<26.
This commit is contained in:
parent
995b20ce14
commit
543175d7a6
@ -8,7 +8,6 @@ import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import java.lang.reflect.Method;
|
||||
import org.kiwix.kiwixmobile.R;
|
||||
import org.kiwix.kiwixmobile.webserver.WebServerHelper;
|
||||
|
||||
@ -32,23 +31,6 @@ public class WifiHotspotManager {
|
||||
wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
|
||||
}
|
||||
|
||||
// This method enables/disables the wifi access point
|
||||
// It is used for API<26
|
||||
public boolean setWifiEnabled(WifiConfiguration wifiConfig, boolean enabled) {
|
||||
try {
|
||||
if (enabled) { //disables wifi hotspot if it's already enabled
|
||||
wifiManager.setWifiEnabled(false);
|
||||
}
|
||||
|
||||
Method method = wifiManager.getClass()
|
||||
.getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
|
||||
return (Boolean) method.invoke(wifiManager, wifiConfig, enabled);
|
||||
} catch (Exception e) {
|
||||
Log.e(this.getClass().toString(), "", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//Workaround to turn on hotspot for Oreo versions
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
public void turnOnHotspot() {
|
||||
@ -103,87 +85,20 @@ public class WifiHotspotManager {
|
||||
return hotspotReservation != null;
|
||||
}
|
||||
|
||||
// This method returns the current state of the Wifi access point
|
||||
private WIFI_AP_STATE_ENUMS getWifiApState() {
|
||||
try {
|
||||
Method method = wifiManager.getClass().getMethod("getWifiApState");
|
||||
|
||||
int tmp = ((Integer) method.invoke(wifiManager));
|
||||
|
||||
// Fix for Android 4
|
||||
if (tmp >= 10) {
|
||||
tmp = tmp - 10;
|
||||
}
|
||||
|
||||
return WIFI_AP_STATE_ENUMS.class.getEnumConstants()[tmp];
|
||||
} catch (Exception e) {
|
||||
Log.e(this.getClass().toString(), "", e);
|
||||
return WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
//This method returns if wifi access point is enabled or not
|
||||
public boolean isWifiApEnabled() {
|
||||
return getWifiApState() == WIFI_AP_STATE_ENUMS.WIFI_AP_STATE_ENABLED;
|
||||
}
|
||||
|
||||
//This method is to get the wifi ap configuration
|
||||
private WifiConfiguration getWifiApConfiguration() {
|
||||
try {
|
||||
Method method = wifiManager.getClass().getMethod("getWifiApConfiguration");
|
||||
return (WifiConfiguration) method.invoke(wifiManager);
|
||||
} catch (Exception e) {
|
||||
Log.e(this.getClass().toString(), "", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//This method is to set the wifi ap configuration
|
||||
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {
|
||||
try {
|
||||
Method method =
|
||||
wifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class);
|
||||
return (Boolean) method.invoke(wifiManager, wifiConfig);
|
||||
} catch (Exception e) {
|
||||
Log.e(this.getClass().toString(), "", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void hotspotDetailsDialog() {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
||||
WebServerHelper webServerHelper = new WebServerHelper(context);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||
webServerHelper.startServerDialog();
|
||||
});
|
||||
} else {
|
||||
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||
final Handler handler = new Handler();
|
||||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
webServerHelper.startServerDialog();
|
||||
}
|
||||
}, 6000);
|
||||
});
|
||||
}
|
||||
|
||||
builder.setTitle(context.getString(R.string.hotspot_turned_on));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
builder.setMessage(
|
||||
context.getString(R.string.hotspot_details_message) + "\n" + context.getString(
|
||||
R.string.hotspot_ssid_label) + " " + currentConfig.SSID + "\n" + context.getString(
|
||||
R.string.hotspot_pass_label) + " " + currentConfig.preSharedKey);
|
||||
} else {
|
||||
currentConfig = getWifiApConfiguration();
|
||||
builder.setMessage(
|
||||
context.getString(R.string.hotspot_details_message) + "\n" + context.getString(
|
||||
R.string.hotspot_ssid_label) + " " + currentConfig.SSID + "\n" + context.getString(
|
||||
R.string.hotspot_pass_label) + " " + currentConfig.preSharedKey);
|
||||
}
|
||||
|
||||
builder.setCancelable(false);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user