mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-24 05:04:50 -04:00
WRITE_Settings permission not given bug
Handle if write settings permission is not given.
This commit is contained in:
parent
5a8cbb2efc
commit
16e310793d
@ -411,7 +411,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
drawerLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
drawerLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
||||||
|
|
||||||
wifiHotspotManager = new WifiHotspotManager(this);
|
wifiHotspotManager = new WifiHotspotManager(this);
|
||||||
wifiHotspotManager.showWritePermissionSettings();
|
|
||||||
|
|
||||||
serviceIntent = new Intent(this, HotspotService.class);
|
serviceIntent = new Intent(this, HotspotService.class);
|
||||||
}
|
}
|
||||||
@ -955,7 +954,9 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
toggleHotspot();
|
toggleHotspot();
|
||||||
} else {
|
} else {
|
||||||
switchHotspot();
|
if (showWritePermissionSettings()) { //request permission and if already granted switch hotspot.
|
||||||
|
switchHotspot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -1085,14 +1086,13 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
if (wifiHotspotManager.isWifiApEnabled()) {
|
if (wifiHotspotManager.isWifiApEnabled()) {
|
||||||
startService(ACTION_TURN_OFF_BEFORE_O);
|
startService(ACTION_TURN_OFF_BEFORE_O);
|
||||||
} else {
|
} else {
|
||||||
//Check if user's hotspot is enabled
|
|
||||||
if (isMobileDataEnabled(this)) {
|
if (isMobileDataEnabled(this)) {
|
||||||
|
|
||||||
mobileDataDialog();
|
mobileDataDialog();
|
||||||
} else {
|
} else {
|
||||||
startService(ACTION_TURN_ON_BEFORE_O);
|
startService(ACTION_TURN_ON_BEFORE_O);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startHotspotDetails() {
|
public static void startHotspotDetails() {
|
||||||
@ -1154,6 +1154,22 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//To get write permission settings, we use this method.
|
||||||
|
private boolean showWritePermissionSettings() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
||||||
|
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
|
if (!Settings.System.canWrite(this)) {
|
||||||
|
Log.v("DANG", " " + !Settings.System.canWrite(this));
|
||||||
|
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
|
||||||
|
intent.setData(Uri.parse("package:" + this.getPackageName()));
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
this.startActivity(intent);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true; //Permission already given
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("SameReturnValue")
|
@SuppressWarnings("SameReturnValue")
|
||||||
@OnLongClick(R.id.bottom_toolbar_bookmark)
|
@OnLongClick(R.id.bottom_toolbar_bookmark)
|
||||||
boolean goToBookmarks() {
|
boolean goToBookmarks() {
|
||||||
@ -1589,8 +1605,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateWidgets(this);
|
updateWidgets(this);
|
||||||
|
|
||||||
wifiHotspotManager.showWritePermissionSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateBottomToolbarVisibility() {
|
private void updateBottomToolbarVisibility() {
|
||||||
@ -1802,7 +1816,6 @@ public class MainActivity extends BaseActivity implements WebViewCallback,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//Checking the result code for LocationSettings resolution
|
//Checking the result code for LocationSettings resolution
|
||||||
case 101:
|
case 101:
|
||||||
final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
|
final LocationSettingsStates states = LocationSettingsStates.fromIntent(data);
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package org.kiwix.kiwixmobile.wifi_hotspot;
|
package org.kiwix.kiwixmobile.wifi_hotspot;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.WifiConfiguration;
|
import android.net.wifi.WifiConfiguration;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
@ -34,20 +31,6 @@ public class WifiHotspotManager {
|
|||||||
wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
|
wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//To get write permission settings, we use this method.
|
|
||||||
public void showWritePermissionSettings() {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
|
|
||||||
&& Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
||||||
if (!Settings.System.canWrite(this.context)) {
|
|
||||||
Log.v("DANG", " " + !Settings.System.canWrite(this.context));
|
|
||||||
Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS);
|
|
||||||
intent.setData(Uri.parse("package:" + this.context.getPackageName()));
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
this.context.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This method enables/disables the wifi access point
|
// This method enables/disables the wifi access point
|
||||||
// It is used for API<26
|
// It is used for API<26
|
||||||
public boolean setWifiEnabled(WifiConfiguration wifiConfig, boolean enabled) {
|
public boolean setWifiEnabled(WifiConfiguration wifiConfig, boolean enabled) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user