How to request run-time recording permission on Android 6.0?

后端 未结 1 1683
一整个雨季
一整个雨季 2020-12-18 16:18

Since Android 6.0, we need to request permissions during app runtime.

In my app, i\'m using local storage, camera, geolocation and audio recording permissions.

1条回答
  •  遥遥无期
    2020-12-18 16:33

    You need the ti.permissions module and a recompiled version of TiSDK :

    • Go under your Titanium SDK directory eg: /Users/[YOUR USER]/Library/Application Support/Titanium/mobilesdk/osx/
    • Duplicate the 5.2.0.GA directory and rename it as 5.2.0.WhatYouWant
    • Go under android subdir and replace titanium.jar with this jar : https://github.com/AppWerft/Tierstimmenarchiv/blob/master/modules/android/titanium.jar
    • After that in your project, inside the tiapp.xml replace 5.2.0.GA with your new named SDK (5.2.0.WhatYouWant) don't forget to insert inside the tiapp.xml under the node

    and after that, you can request storage permission with this snippet:

    if (!require('ti.permissions').hasPermission('android.permission.RECORD_AUDIO'))
    require('ti.permissions').requestPermissions(['android.permission.RECORD_AUDIO'], function(e) {
        if (e.success != 0)
            Ti.API.debug("Permissions OK");
        else
            Ti.API.warn("Permissions denied");
    });
    

    0 讨论(0)
提交回复
热议问题