Menu

SaleSmartly Android webview对接

You can use webview on Android, SaleSmartly Android webview Demo example, click to download

App Manifest Required Permissions

Copy
 <code>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;
&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
&lt;br&gt;
</code>

Webview basic settings

Copy
 <code class="language-kotlin"> // 启用JavaScript
 webView.settings.javaScriptEnabled = true

  // 启用 localStorage
  webView.settings.domStorageEnabled = true
</code>

Webview handles file upload

For detailed code, please see demo

Copy
 <code class="language-kotlin"> webView.webChromeClient = object : WebChromeClient() {
            override fun onShowFileChooser(
                webView: WebView,
                filePathCallback: ValueCallback&lt;Array&lt;Uri&gt;&gt;,
                fileChooserParams: FileChooserParams
            ): Boolean {
                println(&quot;onShowFileChooser&quot;)
                mUploadMessageAboveL = filePathCallback
                val intent = Intent(fileChooserParams.createIntent())
                intent.addCategory(Intent.CATEGORY_OPENABLE)
                intent.type = &quot;*/*&quot;
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) // 允许多选
                register.launch(Intent.createChooser(intent, &quot;Select File&quot;))

                return true
            }
  }
</code>

Webview handles full screen video playback

For detailed code, please see demo

Copy
 <code class="language-kotlin"> webView.webChromeClient = object : WebChromeClient() {
            override fun onShowFileChooser(
                webView: WebView,
                filePathCallback: ValueCallback&lt;Array&lt;Uri&gt;&gt;,
                fileChooserParams: FileChooserParams
            ): Boolean {
                println(&quot;onShowFileChooser&quot;)
                mUploadMessageAboveL = filePathCallback
                val intent = Intent(fileChooserParams.createIntent())
                intent.addCategory(Intent.CATEGORY_OPENABLE)
                intent.type = &quot;*/*&quot;
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true) // 允许多选
                register.launch(Intent.createChooser(intent, &quot;Select File&quot;))

                return true
            }

            override fun onShowCustomView(view: View, callback: CustomViewCallback) {
                // 当视频请求全屏时,显示自定义视图
                if (customView != null) {
                    callback.onCustomViewHidden()
                    return
                }

                customView = view
                customViewContainer.visibility = View.VISIBLE
                customViewContainer.addView(customView)
                customViewCallback = callback
                webView.visibility = View.GONE
                customViewContainer.bringToFront()
            }

            override fun onHideCustomView() {
                // 当退出全屏时,恢复默认视图
                customView?.let {
                    customViewContainer.removeView(it)
                    customView = null
                    customViewContainer.visibility = View.GONE
                    customViewCallback?.onCustomViewHidden()
                    webView.visibility = View.VISIBLE
                }
            }

            override fun getDefaultVideoPoster(): Bitmap {
                return Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888)
            }

        }
</code>

Frequently asked questions

1. No response when clicking to upload pictures or files

You need to rewrite the "onShowFileChooser" of webview, please refer to the demo for details.

2. Video playback cannot be full screen or an exception occurs after exiting full screen

Use custom view in full screen, hide it after exiting, and display the original view. Please refer to demo for details.

3. Unable to load or display

Please check the network permissions, network status, whether the js imported by the page is correct, and whether the plug-in is enabled. It is recommended to run and test it in the browser first, and then put it into the app for testing after passing.

Please check whether the App intercepts or processes the opened link in other ways.

5. After clicking the link, the browser will jump to the external browser and return to a blank page

Please check how the App handles link redirects

Previous
SaleSmartly iOS Developer Documentation
Next
A Complete Guide to Master Webhooks
Last modified: 2025-05-21Powered by