mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-23 04:33:54 -04:00
Refactor hotspot code for API<26
Remove hotspot code for API<26 from HotspotService.java Remove hotspot code for API<26 from WebServerHelper.java Remove the code for turning on hotspot programmatically for API<26.
This commit is contained in:
parent
543175d7a6
commit
c1d6d9fd96
@ -170,7 +170,6 @@ public class WebServerHelper {
|
|||||||
public void serverStartedDialog() {
|
public void serverStartedDialog() {
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, dialogStyle());
|
||||||
WebServerHelper webServerHelper = new WebServerHelper(context);
|
|
||||||
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
builder.setPositiveButton(android.R.string.ok, (dialog, id) -> {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -20,10 +20,7 @@ import org.kiwix.kiwixmobile.main.MainActivity;
|
|||||||
import org.kiwix.kiwixmobile.utils.Constants;
|
import org.kiwix.kiwixmobile.utils.Constants;
|
||||||
|
|
||||||
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_OFF_AFTER_O;
|
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_OFF_AFTER_O;
|
||||||
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_OFF_BEFORE_O;
|
|
||||||
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_ON_AFTER_O;
|
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_ON_AFTER_O;
|
||||||
import static org.kiwix.kiwixmobile.main.MainActivity.ACTION_TURN_ON_BEFORE_O;
|
|
||||||
import static org.kiwix.kiwixmobile.main.MainActivity.startHotspotDetails;
|
|
||||||
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.stopAndroidWebServer;
|
import static org.kiwix.kiwixmobile.webserver.WebServerHelper.stopAndroidWebServer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,9 +38,7 @@ public class HotspotService extends Service {
|
|||||||
|
|
||||||
@Override public void onCreate() {
|
@Override public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
||||||
hotspotManager = new WifiHotspotManager(this);
|
|
||||||
}
|
|
||||||
stopReceiver = new BroadcastReceiver() {
|
stopReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -60,25 +55,14 @@ public class HotspotService extends Service {
|
|||||||
|
|
||||||
@Override public int onStartCommand(Intent intent, int flags, int startId) {
|
@Override public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case ACTION_TURN_ON_BEFORE_O:
|
|
||||||
if (hotspotManager.setWifiEnabled(null, true)) {
|
|
||||||
startHotspotDetails();
|
|
||||||
updateNotification(getString(R.string.hotspot_running), true);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_TURN_ON_AFTER_O:
|
case ACTION_TURN_ON_AFTER_O:
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
hotspotManager.turnOnHotspot();
|
hotspotManager.turnOnHotspot();
|
||||||
updateNotification(getString(R.string.hotspot_running), true);
|
updateNotification(getString(R.string.hotspot_running), true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ACTION_TURN_OFF_BEFORE_O:
|
|
||||||
if (hotspotManager.setWifiEnabled(null, false)) {
|
|
||||||
stopForeground(true);
|
|
||||||
stopSelf();
|
|
||||||
stopAndroidWebServer();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ACTION_TURN_OFF_AFTER_O:
|
case ACTION_TURN_OFF_AFTER_O:
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
hotspotManager.turnOffHotspot();
|
hotspotManager.turnOffHotspot();
|
||||||
@ -108,9 +92,9 @@ public class HotspotService extends Service {
|
|||||||
builder.setContentIntent(contentIntent)
|
builder.setContentIntent(contentIntent)
|
||||||
.setSmallIcon(R.mipmap.kiwix_icon)
|
.setSmallIcon(R.mipmap.kiwix_icon)
|
||||||
.setWhen(System.currentTimeMillis());
|
.setWhen(System.currentTimeMillis());
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
hotspotNotificationChannel();
|
hotspotNotificationChannel();
|
||||||
}
|
|
||||||
if (showStopButton) {
|
if (showStopButton) {
|
||||||
Intent stopIntent = new Intent(ACTION_STOP);
|
Intent stopIntent = new Intent(ACTION_STOP);
|
||||||
PendingIntent stopHotspot =
|
PendingIntent stopHotspot =
|
||||||
@ -125,12 +109,9 @@ public class HotspotService extends Service {
|
|||||||
buildForegroundNotification(status, stopAction));
|
buildForegroundNotification(status, stopAction));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
private void stopHotspot() {
|
private void stopHotspot() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
hotspotManager.turnOffHotspot();
|
hotspotManager.turnOffHotspot();
|
||||||
} else {
|
|
||||||
hotspotManager.setWifiEnabled(null, false);
|
|
||||||
}
|
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
stopSelf();
|
stopSelf();
|
||||||
stopAndroidWebServer();
|
stopAndroidWebServer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user