久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='TMkGx'></bdo><ul id='TMkGx'></ul>

    <small id='TMkGx'></small><noframes id='TMkGx'>

    <legend id='TMkGx'><style id='TMkGx'><dir id='TMkGx'><q id='TMkGx'></q></dir></style></legend>
      <tfoot id='TMkGx'></tfoot>
      <i id='TMkGx'><tr id='TMkGx'><dt id='TMkGx'><q id='TMkGx'><span id='TMkGx'><b id='TMkGx'><form id='TMkGx'><ins id='TMkGx'></ins><ul id='TMkGx'></ul><sub id='TMkGx'></sub></form><legend id='TMkGx'></legend><bdo id='TMkGx'><pre id='TMkGx'><center id='TMkGx'></center></pre></bdo></b><th id='TMkGx'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TMkGx'><tfoot id='TMkGx'></tfoot><dl id='TMkGx'><fieldset id='TMkGx'></fieldset></dl></div>

    1. 如何使用 kivy 處理 android 運行時權限

      How to handle android runtime permission with kivy(如何使用 kivy 處理 android 運行時權限)

        <i id='W8iiR'><tr id='W8iiR'><dt id='W8iiR'><q id='W8iiR'><span id='W8iiR'><b id='W8iiR'><form id='W8iiR'><ins id='W8iiR'></ins><ul id='W8iiR'></ul><sub id='W8iiR'></sub></form><legend id='W8iiR'></legend><bdo id='W8iiR'><pre id='W8iiR'><center id='W8iiR'></center></pre></bdo></b><th id='W8iiR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='W8iiR'><tfoot id='W8iiR'></tfoot><dl id='W8iiR'><fieldset id='W8iiR'></fieldset></dl></div>

            • <legend id='W8iiR'><style id='W8iiR'><dir id='W8iiR'><q id='W8iiR'></q></dir></style></legend>
            • <tfoot id='W8iiR'></tfoot>
            • <small id='W8iiR'></small><noframes id='W8iiR'>

                <tbody id='W8iiR'></tbody>
                <bdo id='W8iiR'></bdo><ul id='W8iiR'></ul>
                本文介紹了如何使用 kivy 處理 android 運行時權限的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我發現 kivy 是一個非常好的構建跨平臺應用程序的框架,我對 kivy 非常感興趣,只是為了做 android 應用程序,因為我認為 kivy 很容易和舒適.

                I found that kivy is very nice framework to build cross platform application and I am very interested in kivy just to do android application as I think is easy and comfortable in kivy.

                在嘗試了幾個例子之后,我很想知道應該如何處理 kivy 應用程序的 android 運行時權限.

                After trying few examples, I am interested to know how should handle android run time permission for the kivy app.

                實際上我在谷歌上搜索過,但沒有一個可行的例子.我應該回到 android/java 還是使用 kivy 和其他一些 python 庫.

                Actually I had searched on google, but no single working example out there. Should I go back to android / java or it possible with kivy and some other python libs.

                推薦答案

                pyjnius 是要走的路.您必須使用 pyjnius 移植 這些說明.這涉及以下步驟:

                pyjnius is the way to go. You have to port these instructions using pyjnius. This involves the following steps:

                • 不幸的是,對 ContextCompat.checkSelfPermission 的 api 調用是在必須單獨下載的 android sdk 支持庫中實現的,因此,獲取與您的 android API 級別最匹配的版本的 .aar 例如這里.
                • 將其復制到您的項目目錄中并從您的 buildozer.spec 中引用它:

                • Unfortunately the api call to ContextCompat.checkSelfPermission is implemented in the android sdk support library which has to be downloaded seperately, so get the .aar with the version best matching your android API level for example here.
                • copy it into your project dir and reference it from your buildozer.spec:

                android.add_aars = support-v4-26.0.0-alpha1.aar  
                

              • 確保 jinius 符合 buildozer.spec 中的要求

              • make sure jinius is in the requirements in buildozer.spec

                使用以下代碼片段

                注意:這是一個阻塞功能,它會等待權限對話框得到答復.如果應用程序已經擁有權限,該函數會立即返回.因此,例如,如果您想獲得寫入 SD 卡和相機的權限,這都是危險權限",請調用:

                Note: this is a blocking function which waits until the permissions dialog is answered. If the app already has the permission the function returns immediately. So for example if you want to get the permissions for writing to the SD card and for the camera, which are both "dangerous permissions", call:

                perms = ["android.permission.READ_EXTERNAL_STORAGE",
                         "android.permission.WRITE_EXTERNAL_STORAGE",
                         "android.permission.CAMERA"]
                
                haveperms = acquire_permissions(perms)
                

                這里是獲取權限的函數:

                And here the function for acquiring the permissions:

                import time
                import functools
                import jnius
                
                def acquire_permissions(permissions, timeout=30):
                    """
                    blocking function for acquiring storage permission
                
                    :param permissions: list of permission strings , e.g. ["android.permission.READ_EXTERNAL_STORAGE",]
                    :param timeout: timeout in seconds
                    :return: True if all permissions are granted
                    """
                
                    PythonActivity = jnius.autoclass('org.kivy.android.PythonActivity')
                    Compat = jnius.autoclass('android.support.v4.content.ContextCompat')
                    currentActivity = jnius.cast('android.app.Activity', PythonActivity.mActivity)
                
                    checkperm = functools.partial(Compat.checkSelfPermission, currentActivity)
                
                    def allgranted(permissions):
                        """
                        helper function checks permissions
                        :param permissions: list of permission strings
                        :return: True if all permissions are granted otherwise False
                        """
                        return reduce(lambda a, b: a and b,
                                    [True if p == 0 else False for p in map(checkperm, permissions)]
                                    )
                
                    haveperms = allgranted(permissions)
                    if haveperms:
                        # we have the permission and are ready
                        return True
                
                    # invoke the permissions dialog
                    currentActivity.requestPermissions(permissions, 0)
                
                    # now poll for the permission (UGLY but we cant use android Activity's onRequestPermissionsResult)
                    t0 = time.time()
                    while time.time() - t0 < timeout and not haveperms:
                        # in the poll loop we could add a short sleep for performance issues?
                        haveperms = allgranted(permissions)
                
                    return haveperms
                

                可能最干凈的方法是拉皮條 p4a 的 PythonActivity.java 來做到這一點,但現在這個是為我做的.

                Probably the cleanest way would be to pimp p4a's PythonActivity.java to do that but this one does it for me for now.

                這篇關于如何使用 kivy 處理 android 運行時權限的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!
              • 相關文檔推薦

                Get user#39;s current location using GPS(使用 GPS 獲取用戶的當前位置)
                IllegalArgumentException thrown by requestLocationUpdate()(requestLocationUpdate() 拋出的 IllegalArgumentException)
                How reliable is LocationManager#39;s getLastKnownLocation and how often is it updated?(LocationManager 的 getLastKnownLocation 有多可靠,多久更新一次?)
                How to detect Location Provider ? GPS or Network Provider(如何檢測位置提供者?GPS 或網絡提供商)
                Get current location during app launch(在應用啟動期間獲取當前位置)
                locationManager.getLastKnownLocation() return null(locationManager.getLastKnownLocation() 返回 null)

                <i id='6Mqte'><tr id='6Mqte'><dt id='6Mqte'><q id='6Mqte'><span id='6Mqte'><b id='6Mqte'><form id='6Mqte'><ins id='6Mqte'></ins><ul id='6Mqte'></ul><sub id='6Mqte'></sub></form><legend id='6Mqte'></legend><bdo id='6Mqte'><pre id='6Mqte'><center id='6Mqte'></center></pre></bdo></b><th id='6Mqte'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6Mqte'><tfoot id='6Mqte'></tfoot><dl id='6Mqte'><fieldset id='6Mqte'></fieldset></dl></div>
                <legend id='6Mqte'><style id='6Mqte'><dir id='6Mqte'><q id='6Mqte'></q></dir></style></legend>
                    <tbody id='6Mqte'></tbody>

                  <small id='6Mqte'></small><noframes id='6Mqte'>

                      • <bdo id='6Mqte'></bdo><ul id='6Mqte'></ul>
                        <tfoot id='6Mqte'></tfoot>

                          主站蜘蛛池模板: 国产精品高潮呻吟久久 | 免费一区 | 久久看精品| 91精品久久久久久久久中文字幕 | 黄色大片视频 | 国产激情毛片 | 日韩精品在线网站 | 国产精品成人在线播放 | av日韩一区 | 久久国产精品精品国产色婷婷 | caoporn免费| 亚洲一区二区三区在线免费观看 | 欧美日韩在线一区二区 | 欧美一区二区大片 | 亚洲精品电影网在线观看 | 最新国产视频 | 亚洲电影专区 | 一区二区三区在线免费观看 | 96av麻豆蜜桃一区二区 | 蜜桃视频在线观看www社区 | 超碰在线影院 | 免费黄网站在线观看 | 亚州精品成人 | 国产偷久久一级精品60部 | 手机在线一区二区三区 | 精品国产三级 | 欧美日韩精品中文字幕 | 亚洲视频在线观看 | 激情在线视频网站 | 成人美女免费网站视频 | 亚洲精品1区 | 国产在线精品一区二区三区 | 日韩视频在线免费观看 | 婷婷不卡 | 国产精品99久久久久久久久久久久 | 久草色视频 | 毛片片 | 亚洲精品区 | 国产精品久久在线 | 国产精品视频久久 | 99爱免费|