예제 #1
0
 def ask_nicely(self, *permissions):
     from android.permissions import (check_permission, request_permission,
                                      request_permissions)
     request_permissions([
         permission for permission in permissions
         if not check_permission(permission)
     ])
예제 #2
0
파일: main.py 프로젝트: ADutta007/KIVY
    def __init__(self, **kw):

        super().__init__(**kw)
        self.flag = False
        self.chck = 0
        # self.random_points()

        try:
            from android.permissions import request_permissions, Permission

            def callback(permissions, results):
                if all([res for res in results]):
                    print("callback. All permissions granted.")
                    gps.configure(on_location=self.on_location,
                                  on_status=self.on_auth_status)
                    gps.start(10, 0)
                else:
                    print("callback. Some permissions refused.")

            request_permissions([
                Permission.ACCESS_COARSE_LOCATION,
                Permission.ACCESS_FINE_LOCATION, Permission.CAMERA,
                Permission.READ_EXTERNAL_STORAGE,
                Permission.WRITE_EXTERNAL_STORAGE
            ], callback)
        except:
            pass
예제 #3
0
    def send(self, _):
        print("[myDEBUG] Button pressed")
        if not check_permission('android.permission.SEND_SMS'):
            request_permissions([Permission.SEND_SMS])

        sms.send(self.recipient.text, self.message)
        vibrator.vibrate(0.3)
예제 #4
0
 def on_start(self):
     if platform == 'android':
         from android.permissions import request_permissions, Permission
         request_permissions([
             Permission.READ_EXTERNAL_STORAGE,
             Permission.WRITE_EXTERNAL_STORAGE, Permission.CAMERA
         ])
예제 #5
0
    def run(self):

        #get a reference to GpsBlinker,then call blink()
        gps_blinker=App.get_running_app().root.ids.mapview.ids.blinker
        #start blinking the GpsBlinker
        gps_blinker.blink()
        pass

        #Request permission on Android
        if platform == "android":
            from android.permissions import Permission,request_permissions
            def callback(permission,results):
                if all([res for res in results]):
                    print("Got all permissions")
                    from plyer import gps
                    gps.configure(on_location=self.update_blinker_position,
                                  on_status=self.on_auth_status)
                    gps.start(minTime=1000,minDistance=0)

                else:
                    print("Did not get all permissions")

            #we put these two parameter inside of buildozer.spec file
            request_permissions([Permission.ACCESS_COARSE_LOCATION,
                                  Permission.ACCESS_FINE_LOCATION],callback)


        #configure GPS
        if platform == "ios":
            from plyer import gps
            gps.configure(on_location=self.update_blinker_position,
                          on_status=self.on_auth_status)
            gps.start(minTime=1000,minDistance=0)
예제 #6
0
    def run(self):
        if platform == "android":

            from android.permissions import Permission, request_permissions

            def permissions(permission, results):
                if all([res for res in results]):
                    gps.configure(on_location=self.update_pos_android,
                                  on_status=self.permission_status)
                    gps.start(minTime=2000, minDistance=0)
                else:
                    popup = PopupPersonalizado(
                        "Se necesitan permisos de localizacion para disfrutar de los servicios de esta aplicación"
                    )

                    popupWindow = Popup(title="Error permisos de localizacion",
                                        content=popup,
                                        size_hint=(None, None),
                                        size=(400, 400))

                    popupWindow.open()

            request_permissions([
                Permission.ACCESS_COARSE_LOCATION,
                Permission.ACCESS_FINE_LOCATION
            ], permissions)
            app = App.get_running_app()
            app.globals["android"] = True
            Clock.schedule_interval(self.update_pos_android, 3)
        else:
            app = App.get_running_app()
            app.globals["android"] = False
            print(app.globals)
            Clock.schedule_interval(self.update_pos_windows, 3)
예제 #7
0
    def request_android_permissions(self):
        """
        Since API 23, Android requires permission to be requested at runtime.
        This function requests permission and handles the response via a
        callback.
        The request will produce a popup if permissions have not already been
        been granted, otherwise it will do nothing.
        """
        from android.permissions import request_permissions, Permission

        def callback(permissions, results):
            """
            Defines the callback to be fired when runtime permission
            has been granted or denied. This is not strictly required,
            but added for the sake of completeness.
            """
            if all([res for res in results]):
                print("callback. All permissions granted.")
            else:
                print("callback. Some permissions refused.")

        request_permissions([
            Permission.CAMERA, Permission.READ_EXTERNAL_STORAGE,
            Permission.WRITE_EXTERNAL_STORAGE
        ], callback)
예제 #8
0
def writer():
	
	testfile = 'Testing'                 # file with a string
	
	perms = [Permission.WRITE_EXTERNAL_STORAGE, Permission.READ_EXTERNAL_STORAGE]
	
	if  check_permissions(perms)!= True:
		request_permissions(perms)    # get android permissions     
		exit()                        # app has to be restarted; permissions will work on 2nd start
		
	try:
		Logger.info('Got requested permissions')    
		ffolder = os.path.join(primary_external_storage_path(),'KT') #folder name
		fname = os.path.join(ffolder,'testfile.txt')                 #file name
		log(f'writing to: {fname}')
		try:
			os.makedirs(ffolder)
			with open(fname, 'w') as f:        # write testfile
				f.write(testfile)
			return fname
		except Exception as e:
			pass
	
	except:
		log('could not write to external storage ... missing permissions ?')    
예제 #9
0
파일: main.py 프로젝트: AyushUlric/getloc
	def build(self):
		if platform=='android':
			while not check_permission('android.permission.WRITE_EXTERNAL_STORAGE'):
				request_permissions([Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE])
		self.theme_cls.primary_palette = "Red"
		master = Builder.load_file('main.kv')
		return master
예제 #10
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.current_file = None
     self.last_path = None
     if platform == 'android':
         self.last_path = '/storage/emulated/0'
         from android.permissions import request_permissions, Permission
         request_permissions([Permission.READ_EXTERNAL_STORAGE])
     self.cols = 1
     self.size_hint_x = 1
     self.padding = (70, 0)
     self.row_force_default = True
     self.row_default_height = 60
     self.add_widget(Menu(for_screen='key'))
     self.add_widget(Label(text='Use any file as password source', size_hint=(1, None), height=60))
     row = GridLayout(
         cols=2,
         row_force_default=True,
         row_default_height=60
     )
     row.add_widget(Label(text='Alphanumeric only:'))
     self.alnum = CheckBox(size_hint=(None, None), width=40, height=40)
     row.add_widget(self.alnum)
     self.add_widget(row)
     self.selectFile = Button(text='Select file', size_hint=(1, None), height=40)
     self.selectFile.bind(on_press=self.btn_select_file)
     self.add_widget(self.selectFile)
     self.chooser = None
예제 #11
0
    def build(self):
        self.start_osc()

        Environment = autoclass('android.os.Environment')
        sdpath = Environment.getExternalStorageDirectory()
        print(">>>>>>>>>>", repr(sdpath))

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

        layout = BoxLayout(orientation='vertical')

        # Create a button for taking photograph
        self.camaraClick = Button(text="START")
        self.camaraClick.size_hint = (.5, .2)
        self.camaraClick.pos_hint = {'x': .25, 'y': .75}
        self.camaraClick.bind(on_press=self.onCameraClick)
        layout.add_widget(self.camaraClick)

        self.camaraDeclick = Button(text="STOP")
        self.camaraDeclick.size_hint = (.5, .2)
        self.camaraDeclick.pos_hint = {'x': .25, 'y': .75}
        self.camaraDeclick.bind(on_press=self.onCameraDeclick)

        layout.add_widget(self.camaraDeclick)

        # return the root widget

        return layout
예제 #12
0
    def request_android_permissions(self):
        """
        Since API 23, Android requires permission to be requested at runtime.
        This function requests permission and handles the response via a
        callback.
        The request will produce a popup if permissions have not already been
        been granted, otherwise it will do nothing.
        """
        from android.permissions import request_permissions, Permission

        def callback(permissions, results):
            """
            Defines the callback to be fired when runtime permission
            has been granted or denied. This is not strictly required,
            but added for the sake of completeness.
            """
            if all([res for res in results]):
                print("callback. All permissions granted.")
            else:
                print("callback. Some permissions refused.")
                self.gps_status = "Some permissions refused."

            self.available_providers = gps.get_available_providers()

        request_permissions([
            Permission.ACCESS_COARSE_LOCATION, Permission.ACCESS_FINE_LOCATION
        ], callback)
예제 #13
0
    def run(self):
        # Get a reference to GpsBlinker, then call blink()
        gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
        # Start blinking the GpsBlinker
        gps_blinker.blink()

        # Request permissions on Android
        if platform == 'android':
            from android.permissions import Permission, request_permissions

            def callback(permission, results):
                if all([res for res in results]):
                    print("Got all permissions")
                else:
                    print("Did not get all permissions")

            request_permissions([
                Permission.ACCESS_COARSE_LOCATION,
                Permission.ACCESS_FINE_LOCATION
            ], callback)

        # Configure GPS
        if platform == 'android' or platform == 'ios':
            from plyer import gps
            gps.configure(on_location=self.update_blinker_position,
                          on_status=self.on_auth_status)
            gps.start(minTime=1000, minDistance=0)
예제 #14
0
    def run(self):
        """This function is called when the class is called, GpsHandler.run()"""
        # Request permissions on Android
        if platform == 'android':
            from android.permissions import Permission, request_permissions

            def callback(permission, results):
                """Check for any errors, with permissions"""
                if all([res for res in results]):
                    print("Got all permissions")
                else:
                    print("Did not get all permissions")

            request_permissions([
                Permission.ACCESS_COARSE_LOCATION,
                Permission.ACCESS_FINE_LOCATION
            ], callback)

        # Configure GPS
        if platform == 'android' or platform == 'ios':
            self.androidBool = True
            from plyer import gps
            gps.configure(on_location=self.updateGpsLatLon,
                          on_status=self.onAuthStatus)
            gps.start(minTime=1000, minDistance=0)

        else:
            self.androidBool = False
예제 #15
0
    def getPermission(self, type='all'):
        """
        Since API 23, Android requires permission to be requested at runtime.
        This function requests permission and handles the response via a
        callback.
        The request will produce a popup if permissions have not already been
        been granted, otherwise it will do nothing.
        """
        if platform == "android":
            from android.permissions import request_permissions, Permission

            if type == 'all':
                plist = [Permission.ACCESS_COARSE_LOCATION,
                         Permission.ACCESS_FINE_LOCATION, Permission.MANAGE_EXTERNAL_STORAGE]
            if type == 'location':
                plist = [Permission.ACCESS_COARSE_LOCATION,
                         Permission.ACCESS_FINE_LOCATION]
            if type == 'files':
                plist = [Permission.MANAGE_EXTERNAL_STORAGE]

            def callback(permissions, results):
                """
                Defines the callback to be fired when runtime permission
                has been granted or denied. This is not strictly required,
                but added for the sake of completeness.
                """
                if all([res for res in results]):
                    print("callback. All permissions granted.")
                else:
                    print("callback. Some permissions refused.")

            request_permissions(plist, callback)
예제 #16
0
    def request_android_permissions(permissions_list):
        """
        Since API 23, Android requires permission to be requested at runtime.
        This function requests permission and handles the response via a
        callback.
        The request will produce a popup if permissions have not already been
        been granted, otherwise it will do nothing.
        """
        from android.permissions import request_permissions, Permission

        def callback(permissions, results):
            """
            Defines the callback to be fired when runtime permission
            has been granted or denied. This is not strictly required,
            but added for the sake of completeness.
            """
            if all([res for res in results]):
                print("callback. All permissions granted.")
            else:
                print("callback. Some permissions refused.")

        required_permissions = [
            getattr(Permission, p.upper()) for p in permissions_list
        ]

        # required_permissions = [Permission.INTERNET,
        #                         Permission.BLUETOOTH,
        #                         Permission.ACCESS_COARSE_LOCATION,
        #                         Permission.ACCESS_FINE_LOCATION,
        #                         Permission.READ_EXTERNAL_STORAGE,
        #                         Permission.WRITE_EXTERNAL_STORAGE]

        request_permissions(required_permissions, callback)
예제 #17
0
 def build(self):
     if platform == 'android':
         request_permissions([
             Permission.WRITE_EXTERNAL_STORAGE,
             Permission.READ_EXTERNAL_STORAGE
         ])
     return PrintScreen()
예제 #18
0
    def build(self):
        if platform == "android" and not check_permission(
                "android.permission.WRITE_EXTERNAL_STORAGE"):
            request_permissions([Permission.WRITE_EXTERNAL_STORAGE])

        self.ydl_opts["quiet"] = self.config.get("general", "quiet")
        self.ydl_opts["nowarning"] = self.config.get("general", "nowarning")
        self.ydl_opts["ignoreerrors"] = self.config.get(
            "general", "ignoreerrors")
        self.ydl_opts["call_home"] = self.config.get("general", "call_home")
        self.ydl_opts["nocheckcertificate"] = self.config.get(
            "general", "nocheckcertificate")
        self.ydl_opts["prefer_insecure"] = self.config.get(
            "general", "prefer_insecure")
        self.ydl_opts["outtmpl"] = join(
            self.config.get("general", "savedir"),
            self.config.get("general", "filetmpl"),
        )

        if self.config.get("general", "method") == "Preset":
            self.ydl_opts["format"] = self.config.get("general", "preset")
        elif self.config.get("general", "method") == "Custom":
            self.ydl_opts["format"] = self.config.get("general", "custom")

        self.use_kivy_settings = False
        return RootLayout()
예제 #19
0
    def run(self):

        #Blinking on map
        #Get a reference to GpsBlinker, then call blink
        gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
        gps_blinker.blink()
        #запросить разрешение на получение местоположения
        if platform == 'android':
            from android.permissions import Permission, request_permissions

            def callback(permission, results):
                if all([res for res in results]):
                    print("Получены все разрешения")
                else:
                    print("Получены не все разрешения")

            request_permissions([
                Permission.ACCESS_COARSE_LOCATION,
                Permission.ACCESS_FINE_LOCATION
            ], callback)

        #конфигурация gps
        if platform == 'android' or platform == 'ios':
            from plyer import gps
            gps.configure(on_location=self.update_blinker_position,
                          on_status=self.on_auth_status)
            gps.start(minTime=1000, minDistance=0)
예제 #20
0
 def __init__(self):
     self.register_event_type('on_cube_found')
     self.register_event_type('on_paired_cube_found')
     super().__init__()
     self.default_adapter = BluetoothAdapter.getDefaultAdapter()
     self.gatt_callback = None
     if not check_permission('android.permission.ACCESS_COARSE_LOCATION'):
         request_permissions([Permission.ACCESS_COARSE_LOCATION])
예제 #21
0
 def request_gps_permission(self):
     '''Get the user's permission to access gps'''
     if platform == "android":
         request_permissions([Permission.ACCESS_FINE_LOCATION],
                             callback=self.locate_with_gps)
     else:
         notify(title="GPS Needed",
                message="This device does not have a gps")
예제 #22
0
 def on_start(self):
     '''Called when the app starts'''
     # self.fps_monitor_start()
     if platform == 'android':
         from android.permissions import request_permissions, Permission
         request_permissions([
             Permission.INTERNET, Permission.READ_EXTERNAL_STORAGE,
             Permission.WRITE_EXTERNAL_STORAGE
         ])
예제 #23
0
def request_multiple_permissions(permissions: List[str]) -> List[bool]:
    """Returns nothing."""
    if IS_ANDROID:
        from android.permissions import request_permissions, Permission
        permissions_qualified_names = [
            getattr(Permission, permission) for permission in permissions
        ]
        request_permissions(permissions_qualified_names
                            )  # Might freeze app while showing user a popup
예제 #24
0
 def __init__(self, *args, **kwargs):
     super(ScreenModel, self).__init__()
     request_permissions([
         Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE
     ])
     self.checker = Checker()
     self.header = Header()
     self.add_widget(self.checker)
     self.add_widget(self.header)
예제 #25
0
 def file_manager_open(self):
     if platform == 'android':
         request_permissions([
             Permission.WRITE_EXTERNAL_STORAGE,
             Permission.READ_EXTERNAL_STORAGE
         ])
         SD_CARD = primary_external_storage_path()
         self.file_manager.show(SD_CARD)
     else:
         self.file_manager.show("/")
예제 #26
0
    def request_android_permissions(self):

        try:
            from android.permissions import request_permissions, Permission
            try:
                request_permissions([Permission.ACCESS_COARSE_LOCATION,Permission.ACCESS_FINE_LOCATION])
            except:
                self.password.text = "permission denied"
        except:
            self.password.text = "permission denied"
예제 #27
0
    def on_start(self):
        from android.permissions import request_permissions, Permission

        def callback(permissions, results):
            print(permissions, results)

        request_permissions([
            Permission.CAMERA, Permission.WRITE_EXTERNAL_STORAGE,
            Permission.READ_EXTERNAL_STORAGE
        ], callback)
예제 #28
0
def check_request_write_permission(callback=None):
    """
    Android runtime storage permission check & request.
    """
    had_permission = check_write_permission()
    if not had_permission:
        from android.permissions import Permission, request_permissions
        permissions = [Permission.WRITE_EXTERNAL_STORAGE]
        request_permissions(permissions, callback)
    return had_permission
예제 #29
0
def check_request_camera_permission(callback=None):
    """
    Android runtime `CAMERA` permission check & request.
    """
    had_permission = check_camera_permission()
    if not had_permission:
        from android.permissions import Permission, request_permissions
        permissions = [Permission.CAMERA]
        request_permissions(permissions, callback)
    return had_permission
예제 #30
0
파일: main.py 프로젝트: 4D1L-PY/Portfolio
	def on_start(self):
		# Get main Android permissions in order to upload an image file already stored
		from android.permissions import request_permissions, Permission
		def callback(permissions, results):
			print(permissions, results)
		request_permissions([Permission.INTERNET,
			                 Permission.CAMERA,
		                     Permission.WRITE_EXTERNAL_STORAGE,
		                     Permission.READ_EXTERNAL_STORAGE],
		                     callback)
예제 #31
0
    def show_first_form(self):
        global STORAGE

        ip_tab = []
        if netifaces:
            interfaces = netifaces.interfaces()
            for interface in interfaces:
                if interface[:2] in ('wl', 'en', 'et'):
                    ifaddress = netifaces.ifaddresses(interface)
                    if netifaces.AF_INET in ifaddress:
                        inets = ifaddress[netifaces.AF_INET]
                        for inet in inets:
                            if 'addr' in inet:
                                addr = inet['addr']
                                if len(addr.split('.')) == 4:
                                    ip_tab.append(addr)
        else:
            try:
                ip_address = get_ip_address(b'wlan0')
                ip_tab.append(ip_address)
            except:
                pass

        if ip_tab:
            ip_address = ', '.join(ip_tab)
        else:
            ip_address = '-'

        label = Label(text=f"[size=18sp][color=88f][b]PYTIGON - select the application:[/b][/color][/size]\n[size=15sp][color=448](my ip addresses: {ip_address})[/b][/color][/size]",
                      markup=True, halign = 'center')
        self.add_widget(label)

        if not check_permission(Permission.WRITE_EXTERNAL_STORAGE):
            ret = request_permissions(PERMISSION)
            print("python::pytigon::request_permissions", ret)

        init("_schall", schserw_settings.ROOT_PATH, schserw_settings.DATA_PATH, schserw_settings.PRJ_PATH,
             schserw_settings.STATIC_APP_ROOT, [schserw_settings.MEDIA_ROOT, schserw_settings.UPLOAD_PATH])

        base_apps_path = os.path.join(os.path.join(STORAGE, "pytigon"), "prj")
        l = [pos for pos in os.listdir(base_apps_path) if not pos.startswith('_')]
        apps = []
        for prj in l:
            base_apps_path2 = os.path.join(base_apps_path, prj)
            try:
                x = __import__(prj + ".apps")
                if hasattr(x.apps, 'PUBLIC') and x.apps.PUBLIC:
                    apps.append(prj)
            except:
                print("Error importing module: ", prj + ".apps")

        if len(apps) > 1:
            if len(apps) > MAX_SEL_APP:
                dy = MAX_SEL_APP - 1
            else:
                dy = len(apps)

            for pos in apps[:dy]:
                button = Button(id=pos, text=pos, size_hint=(1, 1))
                button.bind(on_release=self.chose_callback)
                self.add_widget(button)

            if len(apps) > MAX_SEL_APP:
                spinner = Spinner(
                    text='Other applications',
                    values=apps[dy:],
                    size_hint=(.5, 1),
                    pos_hint={'center_x': 0.5, }
                )
                spinner.bind(text=self.spinner_callback)
                self.add_widget(spinner)
        else:
            if len(apps) > 0:
                self.on_app_chosen(apps[0])
            else:
                self.on_app_chosen()