Powerful contact management for Android · Save smarter. Export faster.
Auto Contact Saver & Exporter
Tools Features How It Works Export Pricing Download
Get the App →

Category: Android

  • How to Implement a WebView in Android Studio: A Step-by-Step Guide With Code

    WebView is a powerful component in Android that allows you to load and display web pages within your application. This guide will walk you through creating a WebView in your Android app, including all necessary configurations and code snippets. By the end, you’ll have a fully functional WebView capable of loading webpages seamlessly.

    Why Use WebView in Android?

    WebView is ideal for integrating web content, such as displaying:

    • Web-based content or applications.
    • Dynamic content hosted online.
    • HTML and CSS content within the app.

    Let’s get started!

    [adinserter block=”1″]

    Prerequisites

    Before implementing a WebView, ensure you have:

    • Android Studio installed.
    • Basic knowledge of Android development.
    • An Android project ready to modify.

    Step 1: Add Internet Permission

    To allow the app to access the internet, add the following permission to your AndroidManifest.xml file:

    <uses-permission android:name="android.permission.INTERNET" />

    Step 2: Create the XML Layout

    Define the layout for your activity. Include a WebView and a ProgressBar to indicate loading progress.


    Read Also: How to Integrate Firebase Authentication with Google Sign-In in an Android App

    res/layout/activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">
    
        <ProgressBar
            android:id="@+id/progressBar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:visibility="gone" />
    
        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>

    [adinserter block=”2″]

    Step 3: Write the Java Code

    Here’s the complete implementation for your MainActivity.java. This includes WebView configuration, progress bar integration, and back navigation handling.

    MainActivity.java

    public class MainActivity extends AppCompatActivity {

    private WebView webView;
    private ProgressBar progressBar;
    
    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        // Initialize WebView and ProgressBar
        webView = findViewById(R.id.webView);
        progressBar = findViewById(R.id.progressBar);
    
        // Configure WebView settings
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setDomStorageEnabled(true); // Enable local storage
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setUseWideViewPort(true);
    
        // Improve performance
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
    
        // Handle WebView navigation
        webView.setWebViewClient(new WebViewClient());
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                // Show or hide the progress bar
                if (newProgress < 100) {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setProgress(newProgress);
                } else {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });
    
        // Load a webpage
        webView.loadUrl("https://www.google.com");
    }
    
    @Override
    public void onBackPressed() {
        // Handle back navigation for WebView
        if (webView.canGoBack()) {
            webView.goBack();
        } else {
            super.onBackPressed();
        }
    }

    }

    [adinserter block=”3″]

    Step 4: Debugging Tips

    If the WebView does not load the webpage:

    • Verify the URL (e.g., use https://www.example.com).
    • Check your internet connection.

    Key Features of the Implementation

    1. JavaScript Enabled: Ensures modern websites load correctly.
    2. Progress Bar: Improves user experience by showing loading progress.
    3. Back Navigation: Allows users to navigate within the WebView history before exiting.
    4. Performance Optimization: Uses caching and enables local storage for better performance.

    Conclusion

    With this guide, you’ve successfully implemented a WebView in your Android application. This setup ensures a seamless and user-friendly experience for loading web content. Whether you’re displaying a website or integrating web-based features, this WebView implementation is a solid foundation for your Android project.

    Happy coding!

  • How to Integrate Firebase Authentication with Google Sign-In in an Android App

    Introduction

    Firebase Authentication is a robust solution for managing user sign-ins in mobile apps. By integrating it with Google Sign-In, you can provide a seamless and secure login experience for your users. Whether you’re building a chat app, e-commerce platform, or social network, this guide will help you implement Firebase Authentication with Google Sign-In in your Android project.


    Prerequisites

    Before diving into the integration, ensure you have the following:

    • Android Studio installed on your machine.
    • A Firebase account for managing your backend.
    • A basic understanding of Android app development.

    Setting Up Firebase

    Creating a Firebase Project

    1. Go to the Firebase Console.
    2. Click on Add Project and provide a project name.
    3. Follow the setup wizard to complete the project creation.

    Adding Your Android App to Firebase

    1. Navigate to Project Settings > General > Add App.
    2. Enter your app’s package name.
    3. Download the google-services.json file and add it to your app’s app/ directory.

    Adding Firebase to Your Android Project

    To integrate Firebase, include the following in your build.gradle files:

    1. Project-Level build.gradle:

    gradledependencies {
    classpath 'com.google.gms:google-services:4.3.15'
    }
    [adinserter name=”Block 1″]

    1. App-Level build.gradle:

    // Import the Firebase BoM
    implementation platform(‘com.google.firebase:firebase-bom:33.7.0’)

    // TODO: Add the dependencies for Firebase products you want to use
    // When using the BoM, don’t specify versions in Firebase dependencies
    implementation ‘com.google.firebase:firebase-analytics’

    implementation ‘com.google.android.gms:play-services-auth:21.3.0’

    implementation(“com.google.firebase:firebase-auth”)

     

    Configuring Google Sign-In in Firebase

    1. Open the Firebase Console.
    2. Navigate to Authentication > Sign-in Methods.
    3. Enable Google Sign-In and save changes.
    4. Copy the Web client ID under your app’s OAuth 2.0 Client IDs.

    Designing the UI

    Create a simple and attractive UI with a Google Sign-In button. Here’s an example layout in XML:

     

    <LinearLayout
    android:id="@+id/googleSignInBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:background="#E9E9E9">

     

    <ImageView
    android:id=”@+id/imgGLogo”
    android:layout_width=”40dp”
    android:layout_height=”40dp”
    android:src=”@drawable/google_logo”/>


    <TextView
    android:id="@+id/txtSignIn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="6dp"
    android:text="Sign In With Google"
    android:textColor="#0D2A75"
    android:textStyle="bold"/>
    </LinearLayout>

    [adinserter name=”Block 2″]

    Implementing Google Sign-In Logic

    Configuring GoogleSignInOptions

    In your MainActivity:

     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(getString(R.string.default_web_client_id))
    .requestEmail()
    .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

    Authenticating Users with Firebase

    Handling Sign-In

    Trigger the Google Sign-In intent:

     

    private void signIn(){

    Intent signInIntent = mGoogleSignInClient.getSignInIntent(); 

    startActivityForResult(signInIntent, RC_SIGN_IN);

     }

    Authenticating with Firebase

    Upon successful sign-in:

     

    private void handleSignInResult(Task<GoogleSignInAccount> task) {
    try {
    GoogleSignInAccount account = task.getResult(ApiException.class);
    AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
    mAuth.signInWithCredential(credential)
    .addOnCompleteListener(this, task -> {
    if (task.isSuccessful()) {
    FirebaseUser user = mAuth.getCurrentUser();
    Toast.makeText(this, “Welcome, ” + user.getDisplayName(), Toast.LENGTH_SHORT).show();
    }
    });
    } catch (ApiException e) {
    Log.w(“SignInError”, e.getMessage());
    }
    }[adinserter name=”Block 3″]

    Managing User Sessions

    Check User Login Status

    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser != null) {
    // User is logged in
    }

    Sign Out

    mGoogleSignInClient.signOut();
    mAuth.signOut();

    Conclusion

    Integrating Firebase Authentication with Google Sign-In adds a professional touch to your app, ensuring secure and convenient access for users. Follow this guide to streamline the process and offer a great user experience.


    FAQs

    1. How secure is Firebase Authentication?
    Firebase uses industry-standard security measures, ensuring safe user authentication.

    2. Can I use other sign-in methods with Firebase?
    Yes, Firebase supports various methods like email, phone, and social logins.

    3. What happens if a user revokes access?
    Firebase automatically prevents further access to the app for that user.

    4. Is Google Sign-In free to use?
    Yes, Google Sign-In and Firebase Authentication are free, but usage limits apply.

    5. How can I troubleshoot authentication failures?
    Check logs, verify your configuration, and ensure valid SHA-1 keys.

  • Android Studio Manifest merger failed error 2024 (Solved)

    Error:

    Manifest merger failed : Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/ga_ad_services_config) from [com.google.android.gms:play-services-measurement-api:21.5.1] AndroidManifest.xml:32:13-58
    is also present at [com.google.android.gms:play-services-ads-lite:23.0.0] AndroidManifest.xml:92:13-59 value=(@xml/gma_ad_services_config).
    Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.
    tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.

    Recently in android studio most of peoples are getting error about

    Manifest merger failed

    Android Studio Manifest merger failed error 2024

    How to solve this android studio manifest merger issue?

     

    You can solve this android studio manifest merger issue very easily, you need to create <property/> in your androidManifest.xml.

     

     

    <property
    android:name=”android.adservices.AD_SERVICES_CONFIG”
    android:resource=”@xml/gma_ad_services_config”
    tools:replace=”android:resource” />

    AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

    <application
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:enableOnBackInvokedCallback="true"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.EasyListCalculatorAndBills"
    tools:targetApi="31"
    >
    <activity
    android:name=".CalculatorActivity"
    android:exported="false" />
    <activity
    android:name=".History_Activity"
    android:exported="false" />

    <meta-data
    android:name="com.google.android.actions"
    android:resource="@xml/global_tracker" />

    <activity
    android:name=".MainActivity"
    android:exported="true"
    android:launchMode="singleTask"
    android:configChanges="orientation|screenSize">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <meta-data
    android:name="android.app.lib_name"
    android:value="" />
    </activity>

    <provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="com.techtools.easylistcalculatorandbills.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
    android:name="android.support.FILE_PROVIDER_PATHS"
    android:resource="@xml/file_paths" />
    </provider>

    <meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="@string/app_id" />

    <property android:name="android.adservices.AD_SERVICES_CONFIG"
    android:resource="@xml/gma_ad_services_config"
    tools:replace="android:resource" />



    <meta-data
    android:name="com.google.android.gms.analytics.globalConfigResource"
    android:resource="@xml/global_tracker" />
    </application>

    </manifest>
  • How To Create Webview In Android Studio

    How To Create Webview In Android Studio?

    Write In OnCreate():

    mWebView = findViewById(R.id.webview);
    mWebView.setWebViewClient(new myWebViewclient()); // to handle URL redirects in the app
    mWebView.getSettings().setJavaScriptEnabled(true); // to enable JavaScript on web pages
    mWebView.getSettings().setGeolocationEnabled(true); // to enable GPS location on web pages
    mWebView.loadUrl("https://www.GOOGLE.com");

     

    After OnCreate():

    public class myWebViewclient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

    view.loadUrl(url);

    return true;
    }


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);


    final String urls = url;
    if (urls.contains("mailto") || urls.contains("whatsapp") || urls.contains("tel") || urls.contains("sms") || urls.contains("facebook") || urls.contains("truecaller") || urls.contains("twiter")) {
    mWebView.stopLoading();
    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri.parse(urls));
    startActivity(i);


    }


    }

    @Override
    public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    }
    }


    @Override
    public void onBackPressed() {
    if (mWebView.canGoBack()) {
    mWebView.goBack();
    } else {
    super.onBackPressed();
    }
    }
  • How To Enable GPS Location On Webview Android Studio?

    Introduction:

    how to Enable GPS Location On Webview, Location-based services are increasingly important in many mobile applications today. With the help of the robust development tools offered by Android Studio, developers may incorporate web content into their Android apps, including WebView. The user experience can be improved and location-based functionality made available by turning on GPS location in WebView. In this blog article, we’ll show you how to use Android Studio to enable GPS location in WebView.

    https://youtu.be/Mprs0cL_oyQ

    Step 1: Set Up the Project

    Before we begin, ensure that you have Android Studio installed on your machine. Create a new Android project or open an existing one in Android Studio.

    Step 2: Add Permissions to AndroidManifest.xml

    how to enable GPS location on WebView, we need to add the necessary permissions to the AndroidManifest.xml file. Open the file and add the following lines of code

    <uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION” />
    <uses-permission android:name=”android.permission.ACCESS_COARSE_LOCATION” />

    Full Code Of AndroidManifest.xml To Enable GPS Location On Webview

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET"/>

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />


    <application
    android:allowBackup="true"
    android:dataExtractionRules="@xml/data_extraction_rules"
    android:fullBackupContent="@xml/backup_rules"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.Webview"
    tools:targetApi="31">
    <activity
    android:name=".MainActivity"
    android:exported="true">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>

    <meta-data
    android:name="android.app.lib_name"
    android:value="" />
    </activity>
    </application>

    </manifest>

    Step 3 : Set Up the WebView

    In the MainActivity class, create a WebView instance and enable JavaScript and geolocation. The geolocation setting will allow the WebView to access the device’s GPS location.

    mWebView = findViewById(R.id.webview);
    mWebView.setWebViewClient(new WebViewClient()); // to handle URL redirects in the app
    mWebView.getSettings().setJavaScriptEnabled(true); // to enable JavaScript on web pages
    mWebView.getSettings().setGeolocationEnabled(true); // to enable GPS location on web pages

    How To Enable GPS Location On Webview Android Studio?

    Get Upto 80% Discounts On Hostinger

    Step 4: Implement the WebChromeClient

    The WebChromeClient class provides methods to handle JavaScript dialogs, geolocation permission requests, and other web-related actions. Override the onGeolocationPermissionsShowPrompt() method to request permission to access the device’s location.

    mWebView.setWebChromeClient(new WebChromeClient() {

    @Override
    public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
    } else {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
    String latitude = String.valueOf(location.getLatitude());
    String longitude = String.valueOf(location.getLongitude());
    String url = "https://www.example.com?lat=" + latitude + "&long=" + longitude;
    mWebView.loadUrl(url);
    callback.invoke(origin, true, true);
    } else {
    callback.invoke(origin, false, false);
    }
    }
    }




    @Override
    public void onPermissionRequest(PermissionRequest request) {
    if (request.getOrigin().toString().startsWith("https://")) {
    request.grant(new String[]{Manifest.permission.ACCESS_FINE_LOCATION});
    } else {
    super.onPermissionRequest(request);
    }
    }
    });

    Read Also: How To Install WordPress On Hostinger? Step By Step All Guide

    The onGeolocationPermissionsShowPrompt() method is called when the WebView needs to request permission to access the device’s location. Inside this method, we check if the ACCESS_FINE_LOCATION permission has been granted. If not, we request it. If the permission is granted, we get the last known location from the LocationManager and load the web page with the latitude and longitude parameters.

    Get Upto 80% Discounts On Hostinger

    The onPermissionRequest() method is called when the WebView needs to request permission for a specific action. In this case, we check if the request is coming from a secure (https) origin and grant the ACCESS_FINE_LOCATION permission if it is.

    Step 5: Check Location Permission and Load the Web Page

    Before loading the web page, check if the ACCESS_FINE_LOCATION permission has been granted. If it has, load the web page. If not, request the permission.

    // Check if location permission is granted
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // Request location permission if not granted
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
    } else {
    // Load the web page if location permission is granted
    mWebView.loadUrl(url);
    }

    Full Code Of MainActivity.java To Enable GPS Location On Webview

    package com.toptools.webview;

    import androidx.annotation.NonNull;
    import androidx.appcompat.app.AppCompatActivity;
    import android.Manifest;
    import android.content.Context;
    import android.content.Intent;
    import android.content.pm.PackageManager;
    import android.graphics.Bitmap;
    import android.location.Location;
    import android.location.LocationManager;
    import android.net.Uri;
    import android.os.Bundle;
    import android.webkit.GeolocationPermissions;
    import android.webkit.PermissionRequest;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    import androidx.core.app.ActivityCompat;

    public class MainActivity extends AppCompatActivity {

    private WebView mWebView;

    private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
    String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mWebView = findViewById(R.id.webview);
    mWebView.setWebViewClient(new WebViewClient()); // to handle URL redirects in the app
    mWebView.getSettings().setJavaScriptEnabled(true); // to enable JavaScript on web pages
    mWebView.getSettings().setGeolocationEnabled(true); // to enable GPS location on web pages
    mWebView.setWebChromeClient(new WebChromeClient() {

    @Override
    public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
    if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
    } else {
    LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (location != null) {
    String latitude = String.valueOf(location.getLatitude());
    String longitude = String.valueOf(location.getLongitude());
    String url = "https://www.example.com?lat=" + latitude + "&long=" + longitude;
    mWebView.loadUrl(url);
    callback.invoke(origin, true, true);
    } else {
    callback.invoke(origin, false, false);
    }
    }
    }




    @Override
    public void onPermissionRequest(PermissionRequest request) {
    if (request.getOrigin().toString().startsWith("https://")) {
    request.grant(new String[]{Manifest.permission.ACCESS_FINE_LOCATION});
    } else {
    super.onPermissionRequest(request);
    }
    }
    });
    // Check if location permission is granted
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
    // Request location permission if not granted
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, LOCATION_PERMISSION_REQUEST_CODE);
    } else {
    // Load the web page if location permission is granted
    mWebView.loadUrl(url);
    }


    mWebView.loadUrl("https://www.GOOGLE.com");
    }

    public class myWebViewclient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

    view.loadUrl(url);

    return true;
    }


    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
    super.onPageStarted(view, url, favicon);


    final String urls = url;
    if (urls.contains("mailto") || urls.contains("whatsapp") || urls.contains("tel") || urls.contains("sms") || urls.contains("facebook") || urls.contains("truecaller") || urls.contains("")) {
    mWebView.stopLoading();
    Intent i = new Intent();
    i.setAction(Intent.ACTION_VIEW);
    i.setData(Uri.parse(urls));
    startActivity(i);


    }


    }

    @Override
    public void onPageFinished(WebView view, String url) {
    super.onPageFinished(view, url);

    }
    }


    @Override
    public void onBackPressed() {
    if (mWebView.canGoBack()) {
    mWebView.goBack();
    } else {
    super.onBackPressed();
    }
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == LOCATION_PERMISSION_REQUEST_CODE) {
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    mWebView.loadUrl(url); // to load the web page after location permission is granted
    }
    } else {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
    }
    }

    Get Upto 80% Discounts On Hostinger

    Full Code Of activity_main.xml To Enable GPS Location On Webview

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>


    </androidx.constraintlayout.widget.ConstraintLayout>

    Get Upto 80% Discounts On Hostinger