app crash after taking permission from user in android

481 views
Skip to first unread message

Degenerate Tech

unread,
Nov 2, 2020, 10:20:24 AM11/2/20
to Kivy users support
i have written kivy app it working well in android ..but when i have added two lines below 

from android.permissions import request_permissions, Permission 
request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

app in android crashing .please help

Anoop Rana

unread,
Nov 2, 2020, 10:24:16 AM11/2/20
to kivy-...@googlegroups.com
Yup the same issue i faced two years back.The solution would be  like just add this in your main loop

        from android.permissions import request_permissions, Permission
        request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
Note: Also make sure to give the permission in .spec file also.Then only it will work.

--
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/1521103a-9f3c-42a3-806e-1a52b1aaed24o%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 10:26:01 AM11/2/20
to Kivy users support
main loop mean where ?
within build method ?


On Monday, November 2, 2020 at 8:54:16 PM UTC+5:30, Anoop Rana wrote:
Yup the same issue i faced two years back.The solution would be  like just add this in your main loop

        from android.permissions import request_permissions, Permission
        request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
Note: Also make sure to give the permission in .spec file also.Then only it will work.

On Mon, Nov 2, 2020 at 8:50 PM Degenerate Tech <sksah...@gmail.com> wrote:
i have written kivy app it working well in android ..but when i have added two lines below 

from android.permissions import request_permissions, Permission 
request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

app in android crashing .please help

--
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-...@googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 10:29:31 AM11/2/20
to Kivy users support
hey ..thanks now it is working

Anoop Rana

unread,
Nov 2, 2020, 10:31:11 AM11/2/20
to kivy-...@googlegroups.com
Where your app starts.At the very top .
.
Basically you can put it inside your own custom function and whenever you call that function it fill pop up a permission dialog asking for permission.So you can put this wherever you want permission.

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/cd576381-8c61-42f6-a73c-ce9a8557eaaco%40googlegroups.com.

Anoop Rana

unread,
Nov 2, 2020, 10:31:50 AM11/2/20
to kivy-...@googlegroups.com
You're welcome :)

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/ba56ce41-7418-4017-b67d-a6df69e285d1o%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 10:42:59 AM11/2/20
to Kivy users support
######sir it is taking storage permission from user but not taking WRITE_SETTINGS using this i want to change brightness 
class MyApp(App):
def build(self):
try:
from android.permissions import request_permissions, Permission
request_permissions([Permission.WRITE_EXTERNAL_STORAGE,Permission.WRITE_SETTINGS])


except Exception as e:
print(e)
a=GridLayout(cols=2)
a.add_widget(Video_play(self))
#a.add_widget(Video_play(self))
return a
You're welcome :)

Anoop Rana

unread,
Nov 2, 2020, 11:07:03 AM11/2/20
to kivy-...@googlegroups.com
I think you can use Plyer to change/control android's properties like brightness,vibration etc.

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/0afcfac5-befc-43fd-ad0a-797343f5865ao%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 11:10:42 AM11/2/20
to Kivy users support
yes i have use plyer ...but it need WRITE_SETTINGS
i have put in buildozer.spec ..after installing app brightness not changing ..when i have enabled system settings to yes for this app ..manually then it is working 

Anoop Rana

unread,
Nov 2, 2020, 11:17:45 AM11/2/20
to kivy-...@googlegroups.com
You can check if vibration works by giving the app permission by the dialog that we set up.That way we will know if this is not working for only brightness or for both brightness & vibration.
Also can you tell me what changes did you make in your .spec file so that i can tell if something is missing.

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/4f381a68-d8ac-4fa9-b1dc-c33cf922da9co%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 11:35:56 AM11/2/20
to Kivy users support

#####some modification need

https://github.com/kivy/plyer/issues/383

Yes, now there is now problem and no "import plyer" error when running on my android device. However, it seems that my Android 6.0.1 does not accept WRITE_SETTINGS permission so easily. The app crashes as soon as trying to use brightness.set_level() or brightness.current_level() in the example. No problem if I comment out the lines using those.

I found on the Web the following:

"To use WRITE_SETTINGS, based on the docs:

Have the element in the manifest as normal.
Call Settings.System.canWrite() to see if you are eligible to write out settings.
If canWrite() returns false, start up the ACTION_MANAGE_WRITE_SETTINGS activity so the user can agree there to allow your app to actually write to settings."

How can this be implemented in Kivy?

Degenerate Tech

unread,
Nov 2, 2020, 11:36:54 AM11/2/20
to Kivy users support
i don't know java android ...please help 

Anoop Rana

unread,
Nov 2, 2020, 11:44:46 AM11/2/20
to kivy-...@googlegroups.com
Can you show the contents of the .spec file? 

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/0f6cef47-22d3-4098-b4c0-a5065628895do%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 11:57:46 AM11/2/20
to Kivy users support

# (list) Permissions
android.permissions = WRITE_SETTINGS,WRITE_EXTERNAL_STORAGE,READ_EXTERNAL_STORAGE


# (int) Target Android API, should be as high as possible.
android.api = 29

Anoop Rana

unread,
Nov 2, 2020, 12:14:52 PM11/2/20
to kivy-...@googlegroups.com
This looks about right.So the problem is as you said that your android does not allow write permission so easily.As you mentioned,the docs say that you have to first start the said activity and then proceed.

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/804b4ed0-c636-4233-9bca-bf7f6dbdce3eo%40googlegroups.com.

Degenerate Tech

unread,
Nov 2, 2020, 1:02:20 PM11/2/20
to Kivy users support
####can you modify this code ?see yellow portion

from jnius import autoclass
from plyer.facades import Brightness
from android import mActivity

System = autoclass('android.provider.Settings$System')


class AndroidBrightness(Brightness):

    def _current_level(self):

        System.putInt(
            mActivity.getContentResolver(),
            System.SCREEN_BRIGHTNESS_MODE,
            System.SCREEN_BRIGHTNESS_MODE_MANUAL)
        cr_level = System.getInt(
            mActivity.getContentResolver(),
            System.SCREEN_BRIGHTNESS)
        return (cr_level / 255.) * 100

    def _set_level(self, level):
        System.putInt(
            mActivity.getContentResolver(),
            System.SCREEN_BRIGHTNESS,
            (level / 100.) * 255)


def instance():
    return AndroidBrightness()
Reply all
Reply to author
Forward
0 new messages