title: FCM Web convert Android webview
body: <p>Create an FCM reception using JavaScript
  Upload to IIS 10 and link with HTTPS
  Completed PC and mobile testing.
  Its address is <a href="https://car369.net/msg_test.ejs" rel="nofollow noreferrer">https://car369.net/msg_test.ejs</a></p>
  <p>We have both Android and Windows environments
  Try to convert to web view and display.
  However, I get a browser error that doesn't support the test results.</p>
  <p>We try to solve the webview client
  Through Advancedwebview, geckowebview
  I tested it and got the same result.</p>
  <p>how can i this?</p>
  <p><strong>Android ErrodMessage</strong></p>
  <pre><code>I/chromium: [INFO:CONSOLE(1)] &quot;Uncaught FirebaseError: Messaging: This browser 
  doesn't support the API's required to use the firebase SDK. (messaging/unsupported-browser).&quot;, 
  source: https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js (1)
  </code></pre>
  <p><strong>FCM main.ejs</strong></p>
  <pre><code>&lt;script src=&quot;https://www.gstatic.com/firebasejs/7.19.1/firebase-app.js&quot;&gt;&lt;/script&gt;
  &lt;script src='https://www.gstatic.com/firebasejs/7.18.0/firebase-messaging.js'&gt;&lt;/script&gt;
  &lt;script&gt;
  //FCM User Code
  const config = {
      apiKey: &quot;xxxxxxxxxxxx&quot;,
      authDomain: &quot;fir-yr.firebaseapp.com&quot;,
      databaseURL: &quot;https://fir-yr.firebaseio.com&quot;,
      projectId: &quot;fir-yr&quot;,
      storageBucket: &quot;fir-yr.appspot.com&quot;,
      messagingSenderId: &quot;xxxxxxxxxxx&quot;,
      appId: &quot;xxxxxxxxxxx&quot;,
      measurementId: &quot;xxxxxxxxx&quot;
  };
  
  //firebase setting
  firebase.initializeApp(config);
  const onMsg = firebase.messaging();
  
  //Get Token
  function clickToken(){
      onMsg.requestPermission()
          .then(function(){
              return onMsg.getToken();
          })
          .then(function(token){
              console.log(token);
              $('#token').val(token)
          })
          .catch(function(arr){
              alert(arr)
              console.log(&quot;Error Occured&quot;);
              console.log('err',arr);
          });
  }
  &lt;script&gt;
  </code></pre>
  <p><strong>firebase-messaging-sw.js</strong></p>
  <pre><code>importScripts('https://www.gstatic.com/firebasejs/7.18.0/firebase-app.js');
  importScripts('https://www.gstatic.com/firebasejs/7.18.0/firebase-messaging.js');
  
  const config = {
      apiKey: &quot;xxxxxxxxxxxxxxxxxxxxx&quot;,
      authDomain: &quot;fir-yr.firebaseapp.com&quot;,
      databaseURL: &quot;https://fir-yr.firebaseio.com&quot;,
      projectId: &quot;fir-yr&quot;,
      storageBucket: &quot;fir-yr.appspot.com&quot;,
      messagingSenderId: &quot;xxxxxxxxxxxxx&quot;,
      appId: &quot;xxxxxxxxxxxxxxxxxxxx&quot;,
      measurementId: &quot;xxxxxxxxxxxxxxxxx&quot;
  };
  
  //firebase setting
  firebase.initializeApp(config);
  
  const messaging = firebase.messaging();
  
  
  messaging.setBackgroundMessageHandler(function(payload){
      console.log('Background payload :',payload);
      //title contents
      const title = payload.data.title;
      //body contents
      const options = {
          body: payload.data.message,
          icon: payload.data.icon,
          click_action : payload.data.click_action,
          data: {click_action:payload.data.click_action}
      };
      //show message
      return self.registration.showNotification(title,options);
  });
  
  
  //Noti Click Event
  self.addEventListener('notificationclick', function(event) {
      event.notification.close();
  
      console.log('event',event);
      console.log('clients :', clients);
  
      var promise = new Promise(function(resolve) {
          setTimeout(resolve, 1000);
      }).then(function() {
          return clients.openWindow(event.notification.data.click_action);
      });
   
      console.log('promise',promise);
      event.waitUntil(promise);
  
  });
  </code></pre>
  <p><strong>MainActivity.java</strong></p>
  <pre><code>public class MainActivity extends Activity  {
      private WebView myWebView;
      @SuppressLint(&quot;WrongViewCast&quot;)
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          myWebView = (WebView) findViewById(R.id.webView);
  
          WebSettings webSettings = myWebView.getSettings();
          webSettings.setJavaScriptEnabled(true);
          webSettings.setJavaScriptCanOpenWindowsAutomatically(false);
          webSettings.setAllowFileAccessFromFileURLs(true);
          webSettings.setSaveFormData(false);
          webSettings.setSavePassword(false);
          webSettings.setUseWideViewPort(true);
          webSettings.setSupportMultipleWindows(true);
          webSettings.setLoadsImagesAutomatically(true);
          webSettings.setGeolocationEnabled(true);
          webSettings.setDomStorageEnabled(true);
          webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
          myWebView.setWebViewClient(new WebViewClient());
  
          myWebView.setWebChromeClient(new WebChromeClient(){
              @Override
              public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                  return super.onJsAlert(view, url, message, result);
              }
          });
  
          String url = &quot;https://car369.net/msg_test.ejs&quot;;
          myWebView.loadUrl(url);
      }
  }
  </code></pre>
  <p><strong>AndroidManifest.xml</strong></p>
  <pre><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.webview&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;
      android:hardwareAccelerated=&quot;true&quot;
      android:usesCleartextTraffic=&quot;true&quot;
      &gt;
  
      &lt;activity android:name=&quot;.MainActivity&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;meta-data android:name=&quot;android:webkit.WebView.EnableSafeBrowsing&quot;
          android:value=&quot;true&quot;/&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  <p><strong>activity_main.xml</strong></p>
  <pre><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>Thank you for answer!!</p>