Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

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

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.

So, requesting for local storage, camera and geolocation is ok with that snippet : https://github.com/appcelerator-developer-relations/appc-sample-ti510/blob/master/app/controllers/permissions.js

But i've not found how to request for audio recording permission...I actually use titutorial.audiorecorder module for Android and it crashes when i tried to record since Android 6.0 because permission for recording is not enable.

More informations on my environment :

Operating System

Name                        = Mac OS X
  Version                     = 10.11.3
  Architecture                = 64bit
  # CPUs                      = 4
  Memory                      = 17179869184

Node.js
  Node.js Version             = 0.12.7
  npm Version                 = 2.11.3

Titanium CLI
  CLI Version                 = 5.0.6

Titanium SDK
  SDK Version                 = 5.2.0.GA
  SDK Path                    = /Users/****/#/mobilesdk/osx/5.2.0.GA
  Target Platform             = android

Appcelerator Studio 4.5.0.201602170821

tiapp.xml

<manifest>
    <uses-sdk android:minSdkVersion="15"/>
    <uses-sdk android:targetSdkVersion="23"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>
    <uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT"/>
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-feature android:glEsVersion="0x00020000" android:required="true"/>
    <uses-permission android:name="com.mycompany.myapp.permission.MAPS_RECEIVE"/>
...
...

</manifest>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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");
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...