如何使用Kivy/Buildozer在Android上请求ACCESS_SURFACE_FLINGER权限



大家好,首先非常感谢所有在不知情的情况下帮助我的人。对于像我这样的人来说,堆栈溢出真的很珍贵。

我刚开始编程,学习了Python3,看看是否可以,并试图为我女朋友的职业活动开发一个Android应用程序。

我在她的网站上抓取信息,把它们放在JSON文件中,对它们进行一些修改,然后使用Kivy和Float Layout将它们添加到屏幕上。最高级的部分(对我来说(是在android上打电话的功能。

所有这些在我的电脑(Ubuntu或Windows(上都运行得很好,但当它进入Android时,它在启动时崩溃(在"加载"后,我会出现黑屏(。

首先,Buildozer询问了很多需求(你会在.spec文件中看到(,在这个问题解决后,我在另一个被拒绝ACCESS_SURFACE_FLINGER的android权限下运行。我询问了builddozer.spec,但这并不像你在日志上看到的那样好。

我还在我的main.py 中使用了一些代码来询问

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

并且它将该Permission作为无ACCESS_SURFACE_FLINGER参数返回。

你能帮我一把吗?我花了两天时间寻找如何让它发挥作用,但我的技能(和谷歌(还不够。

我的建筑商规格:

[app]
# (str) Title of your application
title = ConcepTruelle
# (str) Package name
package.name = conceptruelle
# (str) Package domain (needed for android/ios packaging)
package.domain = org.conceptruelle
# (str) Source code where the main.py live
source.dir = .
# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas,py
# (str) Application versioning (method 1)
version = 0.1
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3,hostpython3,kivy==master,scrapy,jnius,pyjnius,requests,simplejson,openssl,android,prettyprinter,twisted,w3lib,attrs,lxml,parsel,cssselect,itemadapter,cryptography,pyopenssl,zlib_wrapper,macholib,pydispatch,pydispatcher,libxslt,libxml2,service_identity,pyasn1,pyasn1_modules,google-auth-oauthlib,android.permissions
# (str) Icon of the application
icon.filename = %(source.dir)s/icon.png
# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = portrait
#
# Android specific
#
# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0
# (list) Permissions
android.permissions = ACCESS_SURFACE_FLINGER,INTERNET,ACCEPT_HANDOVER,BROADCAST_STICKY,PROCESS_OUTGOING_CALLS,ACTIVITY_RECOGNITION,WRITE_EXTERNAL_STORAGE
# (int) Target Android API, should be as high as possible.
#android.api = 27
# (int) Minimum API your APK will support.
#android.minapi = 21
# (int) Android SDK version to use
#android.sdk = 20
# (str) Android NDK version to use
#android.ndk = 19b
# (int) Android NDK API to use. This is the minimum API your app will support, it should usually match android.minapi.
#android.ndk_api = 21
# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True
# (str) Android NDK directory (if empty, it will be automatically downloaded.)
#android.ndk_path =
# (str) Android SDK directory (if empty, it will be automatically downloaded.)
#android.sdk_path =
# (str) ANT directory (if empty, it will be automatically downloaded.)

我的日志:

10-26 17:12:09.463  9229  9229 V SDL     : nativeSetupJNI()
10-26 17:12:09.466  9229  9229 V SDL     : AUDIO nativeSetupJNI()
10-26 17:12:09.468  9229  9229 V SDL     : CONTROLLER nativeSetupJNI()
10-26 17:12:09.494  9229  9229 D hidapi  : Initializing Bluetooth
10-26 17:12:09.495  9229  9229 D hidapi  : Couldn't initialize Bluetooth, missing android.permission.BLUETOOTH
10-26 17:12:09.525  9229  9229 V PythonActivity: Setting env vars for start.c and Python to use
10-26 17:12:09.525  9229  9229 V PythonActivity: Access to our meta-data...
10-26 17:12:09.529  9229  9229 I PythonActivity: Surface will NOT be transparent
10-26 17:12:09.529  9229  9229 V PythonActivity: onResume()
10-26 17:12:09.530  9229  9229 V SDL     : onResume()
10-26 17:12:09.557   604   942 W ServiceManager: Permission failure: android.permission.ACCESS_SURFACE_FLINGER from uid=10182 pid=9229
10-26 17:12:09.558   604   942 D PermissionCache: checking android.permission.ACCESS_SURFACE_FLINGER for uid=10182 => denied (814 us)
10-26 17:12:09.562  9229  9229 V SDL     : surfaceCreated()
10-26 17:12:09.562  9229  9229 V SDL     : surfaceChanged()
10-26 17:12:09.563  9229  9229 V SDL     : pixel format RGB_565
10-26 17:12:09.565  9229  9229 V SDL     : Window size: 1080x1731
10-26 17:12:09.565  9229  9229 V SDL     : Device size: 1080x1920
10-26 17:12:09.578  9229  9229 V SDL     : nativeResume()
10-26 17:12:09.579  9229  9326 V SDL     : Running main function SDL_main from library /data/app/org.conceptruelle.conceptruelle-OBg7Tkf0OmcdRT4L0eMfDQ==/lib/arm/libmain.so
10-26 17:12:09.579  9229  9326 V PythonActivity: appConfirmedActive() -> preparing loading screen removal
10-26 17:12:09.580  9229  9326 V SDL     : nativeRunMain()
10-26 17:12:09.582  9229  9326 I python  : Initializing Python for Android
10-26 17:12:09.582  9229  9326 I python  : Setting additional env vars from p4a_env_vars.txt
10-26 17:12:09.583  9229  9326 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
10-26 17:12:09.583  9229  9326 I python  : /data/user/0/org.conceptruelle.conceptruelle/files/app
10-26 17:12:09.584  9229  9326 I python  : Preparing to initialize python
10-26 17:12:09.584  9229  9326 I python  : _python_bundle dir exists
10-26 17:12:09.585  9229  9326 I python  : calculated paths to be...
10-26 17:12:09.585  9229  9326 I python  : /data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/stdlib.zip:/data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/modules
10-26 17:12:09.590  9229  9326 I python  : set wchar paths...
10-26 17:12:09.730  9229  9326 I python  : Initialized python
10-26 17:12:09.730  9229  9326 I python  : AND: Init threads
10-26 17:12:09.734  9229  9326 I python  : testing python print redirection
10-26 17:12:09.738  9229  9326 I python  : Android path ['.', '/data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/modules', '/data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/site-packages']
10-26 17:12:09.739  9229  9326 I python  : os.environ is environ({'PATH': '/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin', 'DOWNLOAD_CACHE': '/data/cache', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/bouncycastle.jar:/system/framework/apache-xml.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/framework-oahl-backward-compatibility.jar:/system/framework/android.test.base.jar:/system/framework/telephony-ext.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar', 'ANDROID_SOCKET_zygote_secondary': '11', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.conceptruelle.conceptruelle/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.conceptruelle.conceptruelle/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.conceptruelle.conceptruelle/files', 'ANDROID_UNPACK': '/data/user/0/org.conceptruelle.conceptruelle/files/app', 'PYTHONHOME': '/data/user/0/org.conceptruelle.conceptruelle/files/app', 'PYTHONPATH': '/data/user/0/org.conceptruelle.conceptruelle/files/app:/data/user/0/org.conceptruelle.conceptruelle/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'True', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
10-26 17:12:09.742  9229  9326 I python  : Android kivy bootstrap done. __name__ is __main__
10-26 17:12:09.743  9229  9326 I python  : AND: Ran string
10-26 17:12:09.743  9229  9326 I python  : Run user program, change dir and execute entrypoint
10-26 17:12:10.081  9229  9326 I python  : [WARNING] [Config      ] Older configuration version detected (0 instead of 21)
10-26 17:12:10.081  9229  9326 I python  : [WARNING] [Config      ] Upgrading configuration in progress.
10-26 17:12:10.102  9229  9326 I python  : [INFO   ] [Logger      ] Record log in /data/user/0/org.conceptruelle.conceptruelle/files/app/.kivy/logs/kivy_20-10-26_0.txt
10-26 17:12:10.104  9229  9326 I python  : [INFO   ] [Kivy        ] v1.11.1
10-26 17:12:10.105  9229  9326 I python  : [INFO   ] [Kivy        ] Installed at "/data/user/0/org.conceptruelle.conceptruelle/files/app/_python_bundle/site-packages/kivy/__init__.pyc"
10-26 17:12:10.107  9229  9326 I python  : [INFO   ] [Python      ] v3.8.1 (default, Oct 26 2020, 11:01:07) 
10-26 17:12:10.107  9229  9326 I python  : [Clang 8.0.2 (https://android.googlesource.com/toolchain/clang 40173bab62ec7462
10-26 17:12:10.109  9229  9326 I python  : [INFO   ] [Python      ] Interpreter at ""
10-26 17:12:10.111  9229  9326 I python  : [INFO   ] [Logger      ] Purge log fired. Analysing...
10-26 17:12:10.113  9229  9326 I python  : [INFO   ] [Logger      ] Purge finished!
10-26 17:12:14.439  9229  9326 I python  : [INFO   ] [Factory     ] 184 symbols loaded
10-26 17:12:15.352  9229  9326 I python  : [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
10-26 17:12:15.436  9229  9326 I python  : [INFO   ] [Text        ] Provider: sdl2
10-26 17:12:15.520  9229  9326 I python  : [INFO   ] [Window      ] Provider: sdl2
10-26 17:12:15.573  9229  9326 E libEGL  : validate_display:92 error 3008 (EGL_BAD_DISPLAY)
10-26 17:12:15.575  9229  9326 V SDL     : setOrientation() orientation=-1 width=800 height=600 resizable=true hint=
10-26 17:12:15.593  9229  9326 I python  : [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
10-26 17:12:15.597  9229  9326 I python  : [INFO   ] [GL          ] Backend used <sdl2>
10-26 17:12:15.599  9229  9326 I python  : [INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.2 V@258.0 (GIT@8e59954, I0be83d0d26) (Date:09/22/17)'>
10-26 17:12:15.600  9229  9326 I python  : [INFO   ] [GL          ] OpenGL vendor <b'Qualcomm'>
10-26 17:12:15.602  9229  9326 I python  : [INFO   ] [GL          ] OpenGL renderer <b'Adreno (TM) 418'>
10-26 17:12:15.604  9229  9326 I python  : [INFO   ] [GL          ] OpenGL parsed version: 3, 2
10-26 17:12:15.606  9229  9326 I python  : [INFO   ] [GL          ] Texture max size <16384>
10-26 17:12:15.607  9229  9326 I python  : [INFO   ] [GL          ] Texture max units <16>
10-26 17:12:15.724  9229  9326 I python  : [INFO   ] [Window      ] auto add sdl2 input provider
10-26 17:12:15.727  9229  9326 I python  : [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
10-26 17:12:15.855  9229  9326 I python  :  Traceback (most recent call last):
10-26 17:12:15.857  9229  9326 I python  :  2020-10-26 17:12:15 [kivy] WARNING: stderr: Traceback (most recent call last):
10-26 17:12:15.858  9229  9326 I python  :  2020-10-26 17:12:15 [kivy] WARNING: stderr: 2020-10-26 17:12:15 [kivy] WARNING: stderr: Traceback (most recent call last):
10-26 17:12:15.860  9229  9326 I python  :  2020-10-26 17:12:15 [kivy] WARNING: stderr: 2020-10-26 17:12:15 

编辑:

这是代码:

import kivy
kivy.require('1.9.1')
import scrapy
import os
import json
import pprint
import webbrowser
from kivy.app import App
from kivy.config import Config  
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.floatlayout import FloatLayout
from scrapy.crawler import CrawlerProcess
from kivy.lang import Builder
from jnius import autoclass
from jnius import cast
Config.set('graphics', 'resizable', False)  
Builder.load_string("""
<MyLabel1>
    text_size: self.size
    shorten: False
    markup: True
    background_color: 0.7, 0.7, 0.7, .2
    canvas.before:
        Color:
            rgba: self.background_color
        Rectangle:
            pos: self.pos
            size: self.width, 92
<MyLabel2>
    text_size: self.size
    shorten: False
    markup: True
    background_color: 0.9, 0.9, 0.9, .3
    canvas.before:
        Color:
            rgba: self.background_color
        Rectangle:
            pos: self.pos
            size: self.width, 92
<MyTitle>
    markup: True
""")
class MyLabel1(Label):
    """
    A Label class with dark grey background, markups and wrapping
    """
    pass
class MyLabel2(Label):
    """
    A Label class with light grey background, markups and wrapping
    """
    pass
class MyTitle(Label):
    """
    A Label class with markups for the main title
    """
    pass
class AgendaSpider(scrapy.Spider):
    """
    A scraper who retrieve informations on ConcepTruelle's website
    """
    name = "agendaconceptruelle"
    start_urls = [
        'http://conceptruelle.fr/index.php/notre-agenda'
    ]
    while os.path.exists('agenda.json'): os.remove('agenda.json')
    def parse(self, response):
        for agenda in response.css("div.title-header.ic-title-header.ic-float-left"):
            yield {
                'title': agenda.css("a ::text").get(),
            }
        for agenda in response.css("div.title-cat.ic-title-cat.ic-float-right"):
            yield {
                'category': agenda.css(" ::text").get(),
            }
        for agenda in response.css("div.nextdate.ic-next-date.ic-clearfix"):
            yield {
                'date': agenda.css("span ::text").get(),
            }
        for agenda in response.css("div.nextdate.ic-next-date.ic-clearfix"):
            yield {
                'time': agenda.css("span.ic-single-starttime ::text").get(),
            }
        for agenda in response.css("div.place.ic-place"):
            yield {
                'location': agenda.css(" ::text").get(),
            }
        for agenda in response.css("div.descshort.ic-descshort"):
            yield {
                'description': agenda.css(" ::text").get(),
            }
class ConceptruelleApp(App):
    def build(self):
        """
        Scrape ConcepTruelle's website agenda and put it on screen
        4 buttons give access to website, social medias and phone number
        """
        def phonecall(self):
            """
            Make a Phone Call on Android with Jnius
            """
            Intent = autoclass('android.content.Intent')
            Uri = autoclass('android.net.Uri')          
            PythonActivity = autoclass('org.renpy.android.PythonActivity')                                        
            intent = Intent(Intent.ACTION_CALL)         
            intent.setData(Uri.parse("tel:" + "0600000000"))     
            currentActivity = cast('android.app.Activity',                                                        
                PythonActivity.mActivity)
            currentActivity.startActivity(intent)
         
        def website(self):
            """
            Open ConcepTruelle's website
            """
            webbrowser.open("http://conceptruelle.fr/")
        def facebook(self):
            """
            Open ConcepTruelle's Facebook page
            """
            webbrowser.open("https://www.facebook.com/ConcepTruelle")
        def instagram(self):
            """
            Open ConcepTruelle's Instagram page
            """
            webbrowser.open("https://www.instagram.com/conceptruelle")
        
        # Main application : definition of title, labels and buttons put on a Float Layout
        fl = FloatLayout()
        lbl0 = MyTitle(text = "  [size=28][color=000000]L'[/color][color=dd9514][i]Agenda[/i][/color] [color=000000][b]ConcepTruelle[/b][/size][/color]", markup=True, size_hint =(1, .1), pos_hint ={'center_x':.5, 'center_y':.97})
        lbl1 = MyLabel1(text = event_title_1 + "n" + agenda1, size_hint =(1, .5), pos_hint ={'center_x':.5, 'center_y':1.03})
        lbl2 = MyLabel2(text = event_title_2 + "n" + agenda2, size_hint =(1, .5), pos_hint ={'center_x':.5, 'center_y':.86})
        lbl3 = MyLabel1(text = event_title_3 + "n" + agenda3, size_hint =(1, .5), pos_hint ={'center_x':.5, 'center_y':.69})
        lbl4 = MyLabel2(text = event_title_4 + "n" + agenda4, size_hint =(1, .5), pos_hint ={'center_x':.5, 'center_y':.52})
        lbl5 = MyLabel1(text = event_title_5 + "n" + agenda5, size_hint =(1, .5), pos_hint ={'center_x':.5, 'center_y':.35})
        fl.add_widget(lbl0)
        fl.add_widget(lbl1)
        fl.add_widget(lbl2)
        fl.add_widget(lbl3)
        fl.add_widget(lbl4)
        fl.add_widget(lbl5)
        btn1 = Button(text = "Appel", size_hint =(.25, .1), pos_hint ={'center_x':.125, 'center_y':.05})
        btn1.bind(on_press=phonecall)
        btn2 = Button(text = "Site Web", size_hint =(.25, .1), pos_hint ={'center_x':.375, 'center_y':.05})
        btn2.bind(on_press=website)
        btn3 = Button(text = "Facebook", size_hint =(.25, .1), pos_hint ={'center_x':.625, 'center_y':.05})
        btn3.bind(on_press=facebook)
        btn4 = Button(text = "Instagram", size_hint =(.25, .1), pos_hint ={'center_x':.875, 'center_y':.05})
        btn4.bind(on_press=instagram)
        fl.add_widget(btn1)
        fl.add_widget(btn2)
        fl.add_widget(btn3)
        fl.add_widget(btn4)
        return fl
if __name__ == '__main__':
    # using Scrapy to get informations from ConcepTruelle's website and puting it in a JSON file
    process = CrawlerProcess(settings={
        "FEEDS": {
            "agenda.json": {"format": "json"},
        },
    })
    process.crawl(AgendaSpider)
    process.start()
    
    # Opening the created JSON file and using PPRINT to get strings
    with open("agenda.json") as f:
        agenda_list = json.load(f)
        pprint.pprint(agenda_list)
    
    # Modifying the JSON to fit requirements
    for agenda_dict in agenda_list:
        for k,v in agenda_dict.items():
            if v is not None and k == "time":
                agenda_dict[k] = "à " + str(agenda_dict[k])
            if v is None:
                agenda_dict[k] = "de 10:00 à 16:00"
            for k,v in agenda_dict.items():
                if k == "category" and v == "ntttttStagetttt":
                    agenda_dict[k] = "[color=0aa7f5]" + str(agenda_dict[k]) + "[/color]"
                if k == "category" and v == "ntttttAteliertttt":
                    agenda_dict[k] = "[color=8113bd]" + str(agenda_dict[k]) + "[/color]"
                for k,v in agenda_dict.items():
                    agenda_dict[k] = v.replace('t', '')
                    for k,v in agenda_dict.items():
                        agenda_dict[k] = v.replace('n', '')
    
    # dumping the modified JSON file
    with open('agenda.json', 'w') as outfile:
        json.dump(agenda_list, outfile)
    
    # creating titles and labels with the JSON informations
    event_title_1 = str("[size=18] [b]" + agenda_list[5].get("category") + "[/b] [color=000000]-[/color] [b][color=dd9514]" + str(agenda_list[0].get("title")) + "[/b][/color][/size]")
    event_title_2 = str("[size=18] [b]" + agenda_list[6].get("category") + "[/b] [color=000000]-[/color] [b][color=dd9514]" + str(agenda_list[1].get("title")) + "[/b][/color][/size]")
    event_title_3 = str("[size=18] [b]" + agenda_list[7].get("category") + "[/b] [color=000000]-[/color] [b][color=dd9514]" + str(agenda_list[2].get("title")) + "[/b][/color][/size]")
    event_title_4 = str("[size=18] [b]" + agenda_list[8].get("category") + "[/b] [color=000000]-[/color] [b][color=dd9514]" + str(agenda_list[3].get("title")) + "[/b][/color][/size]")
    event_title_5 = str("[size=18] [b]" + agenda_list[9].get("category") + "[/b] [color=000000]-[/color] [b][color=dd9514]" + str(agenda_list[4].get("title")) + "[/b][/color][/size]")
    agenda1 = str("[color=000000][i] " + str(agenda_list[25].get("description")) + "[/i]n Le " + str(agenda_list[10].get("date")) + " " + str(agenda_list[15].get("time")) + "n Lieu : " + str(agenda_list[20].get("location")) + "[/color]")
    agenda2 = str("[color=000000][i] " + str(agenda_list[26].get("description")) + "[/i]n Le " + str(agenda_list[11].get("date")) + " " + str(agenda_list[16].get("time")) + "n Lieu : " + str(agenda_list[21].get("location")) + "[/color]")
    agenda3 = str("[color=000000][i] " + str(agenda_list[27].get("description")) + "[/i]n Le " + str(agenda_list[12].get("date")) + " " + str(agenda_list[17].get("time")) + "n Lieu : " + str(agenda_list[22].get("location")) + "[/color]")
    agenda4 = str("[color=000000][i] " + str(agenda_list[28].get("description")) + "[/i]n Le " + str(agenda_list[13].get("date")) + " " + str(agenda_list[18].get("time")) + "n Lieu : " + str(agenda_list[23].get("location")) + "[/color]")
    agenda5 = str("[color=000000][i] " + str(agenda_list[29].get("description")) + "[/i]n Le " + str(agenda_list[14].get("date")) + " " + str(agenda_list[19].get("time")) + "n Lieu : " + str(agenda_list[24].get("location")) + "[/color]")
    
    # Define main window's background color
    Window.clearcolor = (1, 1, 1, 1)
    
    # Call the main application
    ConceptruelleApp().run()

不返回ACCESS_SURFACE_FLINGER参数,因为该名称中的应用程序没有可用的此类权限。

权限列表位于https://developer.android.com/reference/android/Manifest.permission根据电话,最简单的方法是使用PLYER模块。

相关内容

  • 没有找到相关文章

最新更新