You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there
How to create Webview with working FileChooser, and how to handle back button to return to main App.
Here is my code, Webview opens, it loads webpage, there is image back button at the browser window but when i press it sometimes it return back to main App, some times it close Webview and main App with only error: #00 pc 00225c74 /data/app/org.test.myapp/lib/arm/libpython3.8.so
File chooser does not work!
`from kivy.uix.modalview import ModalView
from android.runnable import run_on_ui_thread
from jnius import autoclass, cast, PythonJavaClass, java_method, MetaJavaClass
class CustomWebChromeClient(WebChromeClient): javaclass = 'android/webkit/WebChromeClient' metaclass = MetaJavaClass
def onShowFileChooser(self, webView, filePathCallback, fileChooserParams):
# Handle file chooser request here
intent = Intent(Intent.ACTION_GET_CONTENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.setType("*/*")
chooserIntent = Intent.createChooser(intent, "Choose a file")
PythonActivity.mActivity.startActivityForResult(chooserIntent, 1)
# Save the callback for handling the selected file
self.filePathCallback = filePathCallback
return True
def onActivityResult(self, requestCode, resultCode, intent):
if requestCode == 1:
if resultCode == -1: # RESULT_OK
# Get the selected file's URI and pass it to the WebView
selected_file_uri = intent.getData()
self.filePathCallback.onReceiveValue(selected_file_uri)
else:
# Handle the case where file selection was canceled by the user
self.filePathCallback.onReceiveValue(None)
class KeyListener(PythonJavaClass): javacontext = 'app' javainterfaces = ['android/view/View$OnKeyListener']
👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.
Hi there
How to create Webview with working FileChooser, and how to handle back button to return to main App.
Here is my code, Webview opens, it loads webpage, there is image back button at the browser window but when i press it sometimes it return back to main App, some times it close Webview and main App with only error: #00 pc 00225c74 /data/app/org.test.myapp/lib/arm/libpython3.8.so
File chooser does not work!
`from kivy.uix.modalview import ModalView
from android.runnable import run_on_ui_thread
from jnius import autoclass, cast, PythonJavaClass, java_method, MetaJavaClass
WebViewA = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
WebChromeClient = autoclass('android.webkit.WebChromeClient')
WebSettings = autoclass('android.webkit.WebSettings')
LayoutParams = autoclass('android.view.ViewGroup$LayoutParams')
ButtonLayoutParams = autoclass('android.widget.FrameLayout$LayoutParams')
LinearLayout = autoclass('android.widget.LinearLayout')
Button = autoclass('android.widget.ImageButton')
KeyEvent = autoclass('android.view.KeyEvent')
ViewGroup = autoclass('android.view.ViewGroup')
DownloadManager = autoclass('android.app.DownloadManager')
DownloadManagerRequest = autoclass('android.app.DownloadManager$Request')
Uri = autoclass('android.net.Uri')
Environment = autoclass('android.os.Environment')
Context = autoclass('android.content.Context')
PythonActivity = autoclass('org.kivy.android.PythonActivity')
View = autoclass('android.view.View')
R = autoclass('android.R$drawable')
OnClickListener = autoclass('android/view/View$OnKeyListener')
HashMap = autoclass('java.util.HashMap')
String = autoclass('java.lang.String')
Color = autoclass('android.graphics.Color')
Intent = autoclass('android.content.Intent')
File = autoclass('java.io.File')
class DownloadListener(PythonJavaClass):
# https://stackoverflow.com/questions/10069050/download-file-inside-webview
javacontext = 'app'
javainterfaces = ['android/webkit/DownloadListener']
class CustomWebChromeClient(WebChromeClient):
javaclass = 'android/webkit/WebChromeClient'
metaclass = MetaJavaClass
def onShowFileChooser(self, webView, filePathCallback, fileChooserParams):
# Handle file chooser request here
class KeyListener(PythonJavaClass):
javacontext = 'app'
javainterfaces = ['android/view/View$OnKeyListener']
class ImageButtonClickListener(PythonJavaClass):
javainterfaces = ['android/view/View$OnClickListener']
def init(self, listener):
super().init()
self.listener = listener
class WebView(ModalView):
# https://developer.android.com/reference/android/webkit/WebView
`
The text was updated successfully, but these errors were encountered: