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

后端 未结 1 1644
一整个雨季
一整个雨季 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 <sdk-version>5.2.0.GA</sdk-version> with your new named SDK (5.2.0.WhatYouWant) don't forget to insert <uses-permission android:name="android.permission.RECORD_AUDIO"/> inside the tiapp.xml under the <android .... > 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)
提交回复
热议问题