android back button not working with webview

379 views
Skip to first unread message

Degenerate Tech

unread,
Sep 5, 2020, 3:02:46 PM9/5/20
to Kivy users support
from kivy.app import App

from kivy.uix.widget import Widget
from kivy.clock import Clock
from jnius import autoclass
from android.runnable import run_on_ui_thread

global webview
WebView = autoclass('android.webkit.WebView')
WebViewClient = autoclass('android.webkit.WebViewClient')
activity = autoclass('org.kivy.android.PythonActivity').mActivity



@run_on_ui_thread
def create_webview(self, *args):

    webview = WebView(activity)
    
    
    settings = webview.getSettings()
    settings.setJavaScriptEnabled(True)
    settings.setUseWideViewPort(True) # enables viewport html meta tags
    settings.setLoadWithOverviewMode(True) # uses viewport
    settings.setSupportZoom(True) # enables zoom
    settings.setBuiltInZoomControls(True) # enables zoom controls
    wvc = WebViewClient()
    webview.setWebViewClient(wvc)
    activity.setContentView(webview)
    webview.loadUrl('https://google.com')






class Wv(Widget):
    def __init__(self, **kwargs):
        super(Wv, self).__init__(**kwargs)
        Clock.schedule_once(create_webview, 0)
        

    
class ServiceApp(App):
def build(self):
web=Wv()
from kivy.base import EventLoop
EventLoop.window.bind(on_keyboard=self.hook_keyboard)
return web
def hook_keyboard(self,window, key, *largs):
if key == 27:
print("hello=================")
print(webview)
return True 



if __name__ == '__main__':
    ServiceApp().run()

Robert Flatt

unread,
Sep 5, 2020, 5:37:35 PM9/5/20
to Kivy users support

Degenerate Tech

unread,
Sep 6, 2020, 12:24:04 AM9/6/20
to Kivy users support
Why Kivy back button is not working here ? as I am using Kivy ...

Degenerate Tech

unread,
Sep 6, 2020, 3:22:00 AM9/6/20
to Kivy users support
I don't know java. and working with pyjnius is hard for me... please imporove plyer .for Bluetooth data transfer WiFi data transfer ..webview...is will be a best library ..

Degenerate Tech

unread,
Sep 6, 2020, 3:34:57 AM9/6/20
to Kivy users support
or please ..is there any complete tutorial for pyjnius ...how to implement different classes for beginners?

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:13:33 AM10/12/20
to Kivy users support
hello i am having difficulty implementing webview on my app (initially had an error, fixed it but app still closes now without any error message, but no webivew displayed). In my previous app, i successfully implemented back button, can you private email me so that we can help ourselves because i do not know how to use this platform.

Degenerate Tech

unread,
Oct 12, 2020, 7:23:28 AM10/12/20
to Kivy users support
put all adb log

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:26:23 AM10/12/20
to kivy-...@googlegroups.com
The log doesn't specify, I just copied your code and it works, guess the problem was the previous code from github. Is there a way to have a private conversation with you?

On Mon, Oct 12, 2020, 12:23 PM Degenerate Tech <sksah...@gmail.com> wrote:
put all adb log

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/64a4e57d-1cd0-45ca-bd2f-ed54c823c758o%40googlegroups.com.

Degenerate Tech

unread,
Oct 12, 2020, 7:30:33 AM10/12/20
to Kivy users support
private conversation mean ??

Degenerate Tech

unread,
Oct 12, 2020, 7:34:19 AM10/12/20
to Kivy users support
by which medium ?

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:35:01 AM10/12/20
to kivy-...@googlegroups.com
A way to reach you without this forum, a direct mode of communication with you because I have some other questions I would like  to ask that doesn't involve webview

On Mon, Oct 12, 2020, 12:30 PM Degenerate Tech <sksah...@gmail.com> wrote:
private conversation mean ??


--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 12, 2020, 7:36:07 AM10/12/20
to Kivy users support
where are you from ?

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:41:48 AM10/12/20
to kivy-...@googlegroups.com
Whatsapp, Twitter, Instagram, Telegram, just any medium that gives a direct communication line 

On Mon, Oct 12, 2020, 12:34 PM Degenerate Tech <sksah...@gmail.com> wrote:
by which medium ?


--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:44:07 AM10/12/20
to kivy-...@googlegroups.com
If you're on instagram, you can reach me with @thirdworldgaming

On Mon, Oct 12, 2020, 12:34 PM Degenerate Tech <sksah...@gmail.com> wrote:
by which medium ?


--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 12, 2020, 7:45:50 AM10/12/20
to Kivy users support
your country ?

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 7:47:06 AM10/12/20
to kivy-...@googlegroups.com
Nigeria

On Mon, Oct 12, 2020, 12:46 PM Degenerate Tech <sksah...@gmail.com> wrote:
your country ?


--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 12, 2020, 10:52:04 AM10/12/20
to Kivy users support
oh ... sorry i can't ...Tell me here .

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 11:07:12 AM10/12/20
to kivy-...@googlegroups.com
Okay, I have multiple questions from my previous app and the one I'm currently working on.
Let me start with the one I'm working on.
The idea is having two pages, page one shows a list of possible links, when you tap on any of them, it takes you to page two where the web page is rendered, hence the need for webview.
The code you dropped earlier works, but how can I use that code for what I want to implement?

On Mon, Oct 12, 2020, 3:52 PM Degenerate Tech <sksah...@gmail.com> wrote:
oh ... sorry i can't ...Tell me here .

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 12, 2020, 11:37:26 AM10/12/20
to Kivy users support
for Android you have to know Java Android and pyjnius . pyjnius is python library you can call Java classes by using it..it is main problem working with Kivy for Android even I don't know pyjnius properly..

Degenerate Tech

unread,
Oct 12, 2020, 11:45:00 AM10/12/20
to Kivy users support
Kivy developer are writing plyer ..which will be a powerfull plyer if they include all functions of Android such as WiFi , Bluetooth, webview,and others.but They are working very slowly....
I don't know java and Android ..Hence I have choosen Kivy python...but now I am facing problems for Android ..

https://pyjnius.readthedocs.io/en/stable/

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 12:05:00 PM10/12/20
to kivy-...@googlegroups.com
What problems are you facing? If it's the back button issue, I can tell you a workaround, it might not be the best practice but it works for me

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 12:06:06 PM10/12/20
to kivy-...@googlegroups.com
As for my question regarding implementing your code on my app, do you have a solution or any pointer that is useful?

Degenerate Tech

unread,
Oct 12, 2020, 12:46:30 PM10/12/20
to Kivy users support
is your problem about kivy UI for your app?
or pakaging into apk ?



On Monday, October 12, 2020 at 9:36:06 PM UTC+5:30, Tamarautukpamobowei Okpongu wrote:
As for my question regarding implementing your code on my app, do you have a solution or any pointer that is useful?

On Mon, Oct 12, 2020, 5:04 PM Tamarautukpamobowei Okpongu <xtreem...@gmail.com> wrote:
What problems are you facing? If it's the back button issue, I can tell you a workaround, it might not be the best practice but it works for me

On Mon, Oct 12, 2020, 4:45 PM Degenerate Tech <sksah...@gmail.com> wrote:
Kivy developer are writing plyer ..which will be a powerfull plyer if they include all functions of Android such as WiFi , Bluetooth, webview,and others.but They are working very slowly....
I don't know java and Android ..Hence I have choosen Kivy python...but now I am facing problems for Android ..

https://pyjnius.readthedocs.io/en/stable/

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-...@googlegroups.com.

Robert Flatt

unread,
Oct 12, 2020, 1:30:42 PM10/12/20
to Kivy users support
The issue is getting back to Python from Webview.

When Webview is displayed it is an Android Activity, not a Python Activity.
So touching the Webview back button sends the touch event to Java not to Python.

To get the back button to have the functionality you desire, create a key event handler in Java,
and use that to switch back to the Python Activity.

But you will be overriding the behavior of the browser back button, which may confuse users.
Consider instead perhaps a gesture event handler in Java to trigger the Activity change.

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 3:30:59 PM10/12/20
to kivy-...@googlegroups.com
My problem is passing a variable (url) from screen one into your webview code which displays the webpage on screen two

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/18c59e38-2da2-4ea0-ac35-998a61a2319eo%40googlegroups.com.

Robert Flatt

unread,
Oct 12, 2020, 5:14:16 PM10/12/20
to Kivy users support
Webview replaces the current screen, or more correctly replaces the Python Activity.
I don't think you can use screens to navigate to/from a Webview, because the screen has been replaced.

Webview aside, Google will show you lots of examples of passing a variable between screens.

Tamarautukpamobowei Okpongu

unread,
Oct 12, 2020, 5:39:14 PM10/12/20
to kivy-...@googlegroups.com
Okay, thanks for the clarification, I'll try to code with that in mind 

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/6f10acce-fc20-4595-baa4-e9dfd36503dbo%40googlegroups.com.

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 2:18:53 AM10/14/20
to kivy-...@googlegroups.com
I have successfully used a variable to determine which webpage to open via webview, problem is how to exit the webview. Theoretically, I understand your explanation of the app changing from a python activity to a Java one, but I don't know how to code that. If it isn't any trouble, can you show me to to do it? Once the webpage is displayed on via the webview, I want the back button to exit the webview returning back to python (kivy app) activity

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/a9d93f09-a48b-4650-a51e-6c9bf5c526aao%40googlegroups.com.

Robert Flatt

unread,
Oct 14, 2020, 1:08:32 PM10/14/20
to Kivy users support
I've never tried to do this.
Curious I took a quick look when your question came up.
My approach would be to make a keyboard event listener using pyjnius.
But the detailed issues I have not experimented with and are unknown to me.

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 1:12:37 PM10/14/20
to kivy-...@googlegroups.com
I have no idea how to use pyjnius. The module used is jnius, don't know how to use that either 

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/b062650e-df93-4590-a2ae-390f90415b13o%40googlegroups.com.

Degenerate Tech

unread,
Oct 14, 2020, 2:19:36 PM10/14/20
to Kivy users support
pyjnius is jnius 

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 2:26:36 PM10/14/20
to kivy-...@googlegroups.com
Okay, didn't know. I'm new to it

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c2aa82fe-99c2-44e7-9ab7-754c20ce14ddo%40googlegroups.com.

Degenerate Tech

unread,
Oct 14, 2020, 2:40:53 PM10/14/20
to Kivy users support
have you know java and android ?

Degenerate Tech

unread,
Oct 14, 2020, 2:41:08 PM10/14/20
to Kivy users support
have you know java and android ?

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 2:45:08 PM10/14/20
to kivy-...@googlegroups.com
I don't know any. Just recently learnt python then decided to try out kivy

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/c20c0af9-9bcf-4a13-afb5-e60dab89fed5o%40googlegroups.com.

Degenerate Tech

unread,
Oct 14, 2020, 3:02:15 PM10/14/20
to Kivy users support
i know kivy and python ..but java android is needed to work for android ..hence why should i use kivy ? as java android is needed so i can make android apps with java and android.. 
there is no good tutorial of pyjnius..it is main problem for me. 

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 3:05:28 PM10/14/20
to kivy-...@googlegroups.com
Oh okay, I'm sure you'll find a way.


To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0f0af2c0-a7a2-4446-ac92-6da7d69d9d38o%40googlegroups.com.

Tamarautukpamobowei Okpongu

unread,
Oct 14, 2020, 3:06:46 PM10/14/20
to kivy-...@googlegroups.com
On kivy, is there a way to create a loading animation onscreen while the app fetches data? Usually the kivy app freezes when it fetches data from a database 

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/0f0af2c0-a7a2-4446-ac92-6da7d69d9d38o%40googlegroups.com.

Degenerate Tech

unread,
Oct 14, 2020, 3:15:49 PM10/14/20
to Kivy users support
you can use threading or multiprocessing i think ..

Degenerate Tech

unread,
Oct 14, 2020, 3:18:01 PM10/14/20
to Kivy users support
or use can use kivy.network see it is not freezing like share subscribe 

Tamarautukpamobowei Okpongu

unread,
Oct 15, 2020, 2:35:42 AM10/15/20
to kivy-...@googlegroups.com
Thanks man

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/907e6143-3cf3-429a-a754-61cd62454768o%40googlegroups.com.

Tamarautukpamobowei Okpongu

unread,
Oct 15, 2020, 2:39:24 AM10/15/20
to kivy-...@googlegroups.com
Yup I think I'll have to send you the apk so that you'll see what i mean

To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/907e6143-3cf3-429a-a754-61cd62454768o%40googlegroups.com.

Degenerate Tech

unread,
Oct 15, 2020, 2:44:07 AM10/15/20
to Kivy users support
please tell me how you implement back in webview ...give me your code ..

Tamarautukpamobowei Okpongu

unread,
Oct 15, 2020, 2:49:01 AM10/15/20
to kivy-...@googlegroups.com
I haven't implemented back button for webview, only implemented it for the standard kivy app, I'm having problems implementing it too

On Thu, Oct 15, 2020, 7:44 AM Degenerate Tech <sksah...@gmail.com> wrote:
please tell me how you implement back in webview ...give me your code ..

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 21, 2020, 2:11:56 AM10/21/20
to Kivy users support
please show me your code

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAPEtmFuH9%2BsebBpJ9T8bRZr-3hZAyrNKA8S%2BMRFZ%3DN8%2BkUXH4w%40mail.gmail.com.

Tamarautukpamobowei Okpongu

unread,
Oct 21, 2020, 2:14:40 AM10/21/20
to kivy-...@googlegroups.com
I used kivy window for my first app and binded a function to listen to key 27, it worked for my previous app, but for webview, it didn't work

Degenerate Tech

unread,
Oct 21, 2020, 2:18:42 AM10/21/20
to Kivy users support
I think you should write java back button  code as webview in java activity

Degenerate Tech

unread,
Oct 21, 2020, 2:19:49 AM10/21/20
to Kivy users support

Tamarautukpamobowei Okpongu

unread,
Oct 21, 2020, 2:19:56 AM10/21/20
to kivy-...@googlegroups.com
I do not know how to do that. I don't even know how to start it. I have never written java code

Degenerate Tech

unread,
Oct 21, 2020, 2:22:05 AM10/21/20
to Kivy users support
I also don't know java...we need an expert who know java android and python Kivy .

Tamarautukpamobowei Okpongu

unread,
Oct 21, 2020, 2:28:28 AM10/21/20
to kivy-...@googlegroups.com
We do need that. In the mean time I'm trying to learn flutter using dart, I was told it handles back operations automatically. Dart isn't difficult to learn, it's similar to python in my opinion

On Wed, Oct 21, 2020, 7:22 AM Degenerate Tech <sksah...@gmail.com> wrote:
I also don't know java...we need an expert who know java android and python Kivy .

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 21, 2020, 2:34:48 AM10/21/20
to Kivy users support
yes ..I have learnt flutter ..but. Kivy is more flexible than flutter ..Kivy has big potential but they are developing very slowly for Android.

You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/CAPEtmFtvic_nn4TK%2B7qmNABTSuLnG51TvGn5OVUvQkEgZGY4Lw%40mail.gmail.com.

Tamarautukpamobowei Okpongu

unread,
Oct 21, 2020, 2:43:16 AM10/21/20
to kivy-...@googlegroups.com
Okay, I just started learning it. I think I'll switch between kivy and flutter framework depending on the type of app I intend to build. Kivy is easy to use because of it's structure

Robert Flatt

unread,
Oct 21, 2020, 2:46:46 AM10/21/20
to Kivy users support
 https://stackoverflow.com/questions/6077141/how-to-go-back-to-previous-page-if-back-button-is-pressed-in-webview

Unfortunately solutions of this form don't work with pyjnius because the Java compiler does not see the @override directive.

In case you ask - I don't know how.

Tamarautukpamobowei Okpongu

unread,
Oct 21, 2020, 3:10:53 AM10/21/20
to kivy-...@googlegroups.com
There's no post on stack overflow  regarding this issue

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/csG4NQexasA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+...@googlegroups.com.

Degenerate Tech

unread,
Oct 21, 2020, 4:42:04 AM10/21/20
to Kivy users support
I have written an app .. using Kivymd and flutter ..but line no in kivymd is small and simple.in python than dart flutter.
but main problem with kivy with Android is webview,camera ,WiFi Bluetooth,and others ..Kivy team please imporove plyer
Reply all
Reply to author
Forward
0 new messages