RuntimePermission problem in latest tip?


#1

I have recompiled both IntroJucer and an android app (which works fine on other platforms) and I get a JUCE Assertion failure in juce_android_OpenSL.cpp (153). Is it me or have you done something in that field over the past few weeks ?

I obviously DID check the "Specify Audio Permission  in the manifest" box in IntroJucer project...

<EDIT> I also have checked the manifest file and DO have the


<uses-permission android:name="android.permission.RECORD_AUDIO"/>
 

line in it...


#2

Note that if I declare 0 audio inputs (

        audioDeviceManager->initialise (0, 2, 0, true, String(), 0);

)

the problem disappears (which is normal considering that it occurs due to a non-recognition of audio record permission) and the app runs fine. Also, I don't have the problem on MacOS nor iOS (didn't test it on Win nor Linux).

And the problem did not occur until I downlodaded latest JUCE tip (I previously had

        audioDeviceManager->initialise (2, 2, 0, true, String(), 0);

)

I am using latest version of Android tools (as of March 5, 2016),  and MacOS 10.11.3


#3

Hi,

Yes, this is a restriction added in Android API Level 23 which we now added support for.

Let me explain. In the world of Android M, it's not enough anymore to specify the permission in the manifest. If you compile your app for API Level 23 or higher, you now additinally have to explicitly request that permission at runtime, otherwise Android won't let you use audio inputs. That assert you hit—I just added it to make sure that everyone notices the new way of doing things, instead of wondering why their app's audio input doesn't work on Android M.

Here's how it works:

Instead of 

audioDeviceManager->initialise (2, 2, 0, true, String(), 0);

you now have to write this:

RuntimePermissions::request (
    RuntimePermissions::recordAudio,
    /* >> callback to be called when Android decides to grant you the permissions << */
);

The callback will be called asynchronously. Sorry, that's an Android restriction, because what happens between the request and the callback is that Android will present this dialogue to the user:

The callback is a function with this signature: void callback (bool permissionWasGranted) { ... }  When called, the argument tells you what the user chose, and then you have to react to that, such as actually initialising your audio device manager. The easiest way to achieve this in code is with a lambda, for example like this:

RuntimePermissions::request (
    RuntimePermissions::recordAudio,
    [] (bool wasGranted) {
        int numInputChannels = wasGranted ? 2 : 0;
        sharedAudioDeviceManager->initialise (numInputChannels, 2, 0, true, String(), 0);
    }
);

Read the documentation of RuntimePermissions for more info. If it's still unclear, please post...


#4

Totally clear. Thanx for taking the time to explain.


#5

This seems to work for API Level 23 (Android 6) but failed for Android 21 (5.1).

I had to comment out the

androidRunTimePermissionsCallback (true, ptrToCallback);

line to get it to compile and run. I also had to specify 0 audio input in the audioDeviceManager initialise call.

This is ok for me because in this exampleI don't use audio inputs.

But I suppose this is an abnormal behavior ?


#6

That is odd, if you compile for Android 21 it should just work. There, the whole runtime permissions stuff should compile and then just not do anything.

Maybe you forgot to specify the permission in the app manifest?


#7

Well it is odd but if I only replace 21 with 23 in the IntroJucer project it compiles and runs with no problem.

In both cases I checked the "Specify audio record permission in the manifest" box and the manifest file does contain the uses_permission line. To be honnest, I don't understand why I need that since I am not using audio inputs anyway... But I did it just in case...

I even used the magic "Invalidate caches / Restart" command from the File menu. No more success...

The error I get in the API level 21 case is:

"error: cannot find symbol method androidRuntimePermissionsCallback(boolean,long)"

for the .java file. Which is why it works when I comment out the call as said before.

Could it be a library problem ? I am compiling on Mac0S 10.11.3 with latest updates from Android Studio. Any hint ?


#8

Could you please post the exact code that you use in your app to request the permissions and initialise audio outputs?

Also, do you get the same error if you try to compile the Juce Demo? It uses audio inputs and outputs on Android and compiled just fine for API level 21 last time I checked.


#9

I just tried the Juce Demo and I got the same problem. Works for API level 23, not 21.

I'm going to re-install all API 21 libraries and see what happens. If it works on your side that's the only thing I can think of...


#10

OK let me try this again. I'll post here shortly.


#11

Yes, I can reproduce the problem now with the Juce Demo. I'll fix this as soon as possible!


#12

OK, that was a bug in our Java code. Should be fixed now. Please update to the newest tip, re-Introjuce your app and try again!


#13

Ah !  This was driving me nuts !!! Glad you found the bug (and the fix...) Now of course when I downloaded the tip I bumped against the empty() syndrom... which you fixed in the meantime. So everything's back on tracks now (as far as I can tell...).

Thanks