title: Allow notifications Android webview
body: <p><strong>Context</strong>
  I'm trying to add push notifications that come from my website.
  My code:</p>
  <ul>
  <li>MainActivity.java</li>
  </ul>
  <pre class="lang-java prettyprint-override"><code>package com.example.neurofinance;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.annotation.TargetApi;
  import android.content.Context;
  import android.net.http.SslError;
  import android.os.Build;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.webkit.JavascriptInterface;
  import android.webkit.SslErrorHandler;
  import android.webkit.WebResourceRequest;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebViewClient;
  import android.widget.Toast;
  
  
  
  public class MainActivity extends AppCompatActivity {
  
      public class WebAppInterface {
          Context mContext;
  
          /** Instantiate the interface and set the context */
          WebAppInterface(Context c) {
              mContext = c;
          }
  
          /** Show a toast from the web page */
          @JavascriptInterface
          public void showToast(String toast) {
              Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
          }
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          return true;
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          this.getWindow().getDecorView().setSystemUiVisibility(
  
                  View.SYSTEM_UI_FLAG_LAYOUT_STABLE
  
                          | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
  
                          | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
  
                          | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
  
                          | View.SYSTEM_UI_FLAG_FULLSCREEN);
  
  
  
          WebView webView = findViewById(R.id.webView);
          webView.addJavascriptInterface(new WebAppInterface(this), &quot;Android&quot;);
          
          webView.getSettings().setDomStorageEnabled(true);
  
          webView.getSettings().setJavaScriptEnabled(true);
  
  
  
          webView.getSettings().setUseWideViewPort(true);//setting wide view
          webView.getSettings().setLoadWithOverviewMode(true);//setting default zoomed out view
          webView.setInitialScale(1);
          webView.getSettings().setBuiltInZoomControls(true);//setting zoom controls
  
          webView.loadUrl(&quot;www.URL.com&quot;);
          
  
          WebViewClient webViewClient = new WebViewClient() {
  
              @SuppressWarnings(&quot;deprecation&quot;) @Override
  
              public boolean shouldOverrideUrlLoading(WebView view, String url) {
  
                  view.loadUrl(url);
  
                  return true;
  
              }
  
              @Override
              public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
                  handler.proceed();
              }
  
              @TargetApi(Build.VERSION_CODES.N) @Override
  
              public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
  
                  view.loadUrl(request.getUrl().toString());
  
                  return true;
  
              }
          };
  
          webView.setWebViewClient(webViewClient);
  
          if (Build.VERSION.SDK_INT &gt;= 21)
              webView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
      }
  }
  </code></pre>
  <ul>
  <li>AndroidManifest.xml</li>
  </ul>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      package=&quot;com.example.neurofinance&quot;&gt;
      &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
      &lt;application
          android:allowBackup=&quot;true&quot;
          android:icon=&quot;@mipmap/ic_launcher&quot;
          android:label=&quot;@string/app_name&quot;
          android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
          android:supportsRtl=&quot;true&quot;
          android:theme=&quot;@style/AppTheme&quot;&gt;
          &lt;activity android:name=&quot;.MainActivity&quot;
              android:configChanges=&quot;orientation|keyboardHidden|screenSize&quot;&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
                  &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <ul>
  <li>activity_main.xml</li>
  </ul>
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;WebView
          android:id=&quot;@+id/webView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p><strong>Problem</strong><br />
  I tried code from this <a href="https://stackoverflow.com/a/59282866/12438977">post</a> but it did not help.</p>
  <p>However, I think that I should allow notifications somewhere. I tried to open my website in a browser and it actually asks the permission while my app does not. (left: browser, right: webview)</p>
  <p><a href="https://i.stack.imgur.com/lH5v6.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lH5v6.jpg" alt="enter image description here" /></a></p>