Immersive mode on android KitKat.

463 views
Skip to first unread message

hci...@gmail.com

unread,
Nov 27, 2013, 3:42:35 PM11/27/13
to kivy-...@googlegroups.com
I was wandering if anyone has tried to use the new immersive mode on kitkat with kivy. If so, how is it done?

hci...@gmail.com

unread,
Dec 2, 2013, 2:01:26 PM12/2/13
to kivy-...@googlegroups.com
Bump?

Doug Linder

unread,
Dec 2, 2013, 7:49:53 PM12/2/13
to kivy-...@googlegroups.com
Never tried it, but I can't see why it would be any different from any other java interaction;
http://kivy.org/planet/2012/08/pyjnius-accessing-java-classes-from-python/

(relevant java api link for the curious -> http://developer.android.com/reference/android/view/View.html#setSystemUiVisibility%28int%29)

~
Doug.

hci...@gmail.com

unread,
Dec 3, 2013, 1:44:06 PM12/3/13
to kivy-...@googlegroups.com
The code bellow is what I've tried. But it gives me the following error when I run it on the device, which is a Nexus 7 running android 4.4:

"/main.py", line 84, in build
I/python  (12461):    File "jnius_export_class.pxi", line 147, in jnius.jnius.JavaClass.__init__ (jnius/jnius.c:10916)
I/python  (12461):    File "jnius_export_class.pxi", line 199, in jnius.jnius.JavaClass.call_constructor (jnius/jnius.c:11757)
I/python  (12461):  jnius.jnius.JavaException: No constructor matching your arguments

 I assume this means that it can't find the 'android.view.View' class? That seems weird because that is a standard class with android.
     
       
        from jnius import autoclass

       
# Set to immersive mode on Android
        aView
= autoclass('android.view.View') # This is line 84 where the error is
        view
= aView()
        decorView
= aView.getActivity.getWindow.getDecorView()
       
       
# Set options for view
        uiOptions
= view.SYSTEM_UI_FLAG_LAYOUT_STABLE
        uiOptions
+= view.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
        uiOptions
+= view.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
        uiOptions
+= view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        uiOptions
+= view.SYSTEM_UI_FLAG_FULLSCREEN
        uiOptions
+= view.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
       
       
# Set view to options
        decorView
.setSystemUiVisibility(uiOptions)




Mathieu Virbel

unread,
Dec 4, 2013, 8:20:16 AM12/4/13
to kivy-...@googlegroups.com
The issue is with the aView(), not autoclass.
And the error is "No constructor matching your arguments", if you check
the android documentation, you'll see that yes, you cannot instanciate a
View with no argument. At least, you need to pass the Context.

This is the second time i'm reading an issue like that this week, just
because users don't read the android documentation :)

As for creating a view just to get the current activity, this is wrong.

Using kivy/python-for-android, right now (this might change in the
future), you can get the activity/context instance with:

PythonActivity = autoclass('org.renpy.android.PythonActivity')
context = PythonActivity.mActivity

-> context is an instance of an Activity class, and Activity subclass
Context.

From that point, you can do context.getWindow().getDecorView() etc.

Good luck!


Le 03/12/2013 19:44, hci...@gmail.com a �crit :
> The code bellow is what I've tried. But it gives me the following error
> when I run it on the device, which is a Nexus 7 running android 4.4:
>
> "/main.py", line 84, in build
> I/python (12461): File "jnius_export_class.pxi", line 147, in
> jnius.jnius.JavaClass.__init__ (jnius/jnius.c:10916)
> I/python (12461): File "jnius_export_class.pxi", line 199, in
> jnius.jnius.JavaClass.call_constructor (jnius/jnius.c:11757)
> I/python (12461): jnius.jnius.JavaException: _/No constructor matching
> your arguments/_
>
> I assume this means that it can't find the 'android.view.View' class?
> That seems weird because that is a standard class with android.
>
>
> |
> fromjnius importautoclass
>
> # Set to immersive mode on Android
> aView =autoclass('android.view.View')# This is line 84 where the
> error is
> view =aView()
> decorView =aView.getActivity.getWindow.getDecorView()
>
> # Set options for view
> uiOptions =view.SYSTEM_UI_FLAG_LAYOUT_STABLE
> uiOptions +=view.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
> uiOptions +=view.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
> uiOptions +=view.SYSTEM_UI_FLAG_HIDE_NAVIGATION
> uiOptions +=view.SYSTEM_UI_FLAG_FULLSCREEN
> uiOptions +=view.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
>
> # Set view to options
> decorView.setSystemUiVisibility(uiOptions)
>
> |
>
>
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.

hci...@gmail.com

unread,
Dec 4, 2013, 11:58:50 AM12/4/13
to kivy-...@googlegroups.com
So I guess I misunderstood autoclass. I thought it was used for importing, kind of like we do 'import someClass as ...' in python. The way 'View' is used in the cases I've seen is not through instantiation but by reference and using objects it contains. To make that clear, after an import of 'android.view.View' you will access the display mode flags like this: 'uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN'. Once you've added all the flags to the 'uiOptions' variable you then send them as a argument to the 'setSystemUiVisibility()' method of 'decorView'. 
   From your examples I can gather how to do everything, except I am still fuzzy on how I can get access to the 'View' flags.


On Wednesday, November 27, 2013 12:42:35 PM UTC-8, hci...@gmail.com wrote:

Mathieu Virbel

unread,
Dec 4, 2013, 2:03:31 PM12/4/13
to kivy-...@googlegroups.com
Flags are a static final int within the View.

So either:
View = autoclass('android.view.View')
and use View.SYSTEM_UI_FLAG_FULLSCREEN

Or use the numeric value directly: 0x4

Mathieu

Le 04/12/2013 17:58, hci...@gmail.com a �crit :
> So I guess I misunderstood autoclass. I thought it was used for
> importing, kind of like we do 'import someClass as ...' in python. The
> way 'View' is used in the cases I've seen is not through instantiation
> but by reference and using objects it contains. To make that clear,
> after an import of 'android.view.View' you will access the display mode
> flags like this: 'uiOptions ^= _/View/_.SYSTEM_UI_FLAG_FULLSCREEN'. Once
> you've added all the flags to the 'uiOptions' variable you then send
> them as a argument to the 'setSystemUiVisibility()' method of 'decorView'.
> From your examples I can gather how to do everything, except I am
> still fuzzy on how I can get access to the 'View' flags.
>
> On Wednesday, November 27, 2013 12:42:35 PM UTC-8, hci...@gmail.com wrote:
>
> I was wandering if anyone has tried to use the new immersive mode on
> kitkat with kivy. If so, how is it done?
>

hci...@gmail.com

unread,
Dec 4, 2013, 2:53:54 PM12/4/13
to kivy-...@googlegroups.com
Thanks for the quick reply. But won't that just give me the same error I had in the first place?


On Wednesday, November 27, 2013 12:42:35 PM UTC-8, hci...@gmail.com wrote:

Doug Linder

unread,
Dec 4, 2013, 8:01:20 PM12/4/13
to kivy-...@googlegroups.com
I think you're misunderstanding exactly what he meant~

Get a view *instance* like this:

PythonActivity = autoclass('org.renpy.android.PythonActivity')
context = PythonActivity.mActivity
view_instance = context.getWindow().getDecorView() / whatever

That's the already existing view that you want to modify. Then modify it by going:
View = autoclass('android.view.View')   <--- This is class
flag = View.SYSTEM_UI_FLAG_FULLSCREEN

And apply the flag:
view_instance.setSystemUiVisibility(flag)

or:
view_instance.setSystemUiVisibility(0x00ff) <--- or whatever

~
Doug.

hci...@gmail.com

unread,
Dec 6, 2013, 4:33:34 PM12/6/13
to kivy-...@googlegroups.com
Well, after using that I don't have the same error, that's a step;} Now it won't run I think because it doesn't recognize the flags. I would say that this is because of using an older API, but I've been using API level 19. Not sure where to go from here. I've followed the guides from google to the letter on this one. I even modified the PythonActivity.java file to see if maybe it needed to called from the onCreate method but ran into the same ( Full Java exception stack) error. Any ideas?


On Wednesday, November 27, 2013 12:42:35 PM UTC-8, hci...@gmail.com wrote:

Tony Beville

unread,
Mar 8, 2016, 3:36:18 PM3/8/16
to Kivy users support

Resurrecting an old thread here!  I'm building an app where I want to go into a reader mode that hides the top and bottom bars.  I've not had any luck to getting any of the methods that I've found on this board to work (or even not crash)   I'm testing on a phone with Android 6.0.1.

Has anyone here been able to put their Kivy app on Android into immersive mode?



hci...@gmail.com

unread,
Nov 9, 2016, 2:46:32 PM11/9/16
to Kivy users support
After doing this with a work around I decided to give pyjnius another try and this time got it working. It has to be run on the main thread using the activity method runOnUiThread(). To do this I used Tito's runnable.py class found here: https://gist.github.com/tito/5844528.

Put that file in your project directory and after importing it and autoclass from jnius use this code:

@run_on_ui_thread
def set_fullscreen():
    PythonActivity = autoclass('org.renpy.android.PythonActivity')
    Context = PythonActivity.mActivity
    view_instance = Context.getWindow().getDecorView()
    View = autoclass('android.view.View')
    flag = 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 \
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    view_instance.setSystemUiVisibility(flag)

When you call the method set_fullscreen or whatever you decide to call it the app should go to immersive sticky mode.

ngoone...@gmail.com

unread,
Jan 18, 2017, 8:10:29 PM1/18/17
to Kivy users support
Thanks for that. I'm trying to do the same thing, but keep hitting the following:-

01-19 09:07:24.739 16118 16356 F art     : art/runtime/java_vm_ext.cc:410]   native: #08 pc 00027353  /data/data/org.test.songprez/files/app/lib/python2.7/site-packages/jnius/jnius.so (???)
01-19 09:07:25.195 16118 16356 F art     : art/runtime/runtime.cc:372]   native: #11 pc 00027353  /data/data/org.test.songprez/files/app/lib/python2.7/site-packages/jnius/jnius.so (???)
01-19 09:07:25.196 16118 16356 F art     : art/runtime/runtime.cc:372]   native: #13 pc 00027353  /data/data/org.test.songprez/files/app/lib/python2.7/site-packages/jnius/jnius.so (???)
01-19 09:07:25.198 16118 16356 F art     : art/runtime/runtime.cc:372]   native: #02 pc 000c995d  /data/app/org.test.songprez-1/lib/arm/libpython2.7.so (PyThread_acquire_lock+52)
01-19 09:07:25.397   721   721 F DEBUG   :     #13 pc 00027353  /data/data/org.test.songprez/files/app/lib/python2.7/site-packages/jnius/jnius.so

I included the linked runnable.py, def-ed a set_fullscreen() function exactly as given here. When my app calls it I see the above lines in logcat, and then it crashes.

Using buildozer with android_new and added jnius to the requirements array.

Pkore

unread,
Jan 18, 2017, 8:23:16 PM1/18/17
to Kivy users support
I'm not sure about the 'android_new' command. I just run 'buildozer android debug deploy run' in the app directory. Are you using the buildozer VM? That includes the recipe for deploying with pyjnius. And remember in the requirements of your spec it is 'pyjnius' not 'jnius'.
Reply all
Reply to author
Forward
0 new messages