Android-SmartWebView icon indicating copy to clipboard operation
Android-SmartWebView copied to clipboard

loading webview immediately after granting of permission

Open husaindevelop opened this issue 2 years ago • 1 comments

In our android webview app, We ask for read_contacts, location, camera, audio permissions at a time on initialization of app. What happens is that simultaneously the webview url is also loaded. This causes some data like contacts json object not to be passed to webview in the first load.

What we expect from the app is to load the webview url immediately after user allows, grants permissions for the above only and not before that. We tried using onRequestPermissionsResult for achieving this, but unable to do so. The code we have tried is as given hereunder:

@Override
	public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
		if (requestCode == 1) {
			// Use this method to check if all the permissions are GRANTED.
			if (areAllPermissionsGranted(grantResults)) {
				get_location();


			}
		}
	}

	// Method to check if all the results are GRANTED.
	private Boolean areAllPermissionsGranted(int[] grantResults) {
		boolean isGranted = false;
		if (grantResults.length > 0) {
			for (int grantResult : grantResults) {
				if (grantResult == PackageManager.PERMISSION_GRANTED) {
					isGranted = true;
					aswm_view(ASWV_URL, false, asw_error_counter);
				} else {
					// if a single permission is NOT_GRANTED, return from the method.
					return false;
				}
			}
		}
		return isGranted;
	}
	

Shall appreciate should you help us out on this issue.

husaindevelop avatar Jun 28 '22 01:06 husaindevelop

we already have a function called check_permission where you can put individual request code and create a simple condition to whether load the webview URL or do something of your own.

mgks avatar Oct 06 '22 08:10 mgks