We are about to switch to a new forum software. Until then we have removed the registration on this forum.
In an app that I developed, it requires the mic permission of the user. I've added the RECORD_AUDIO permissions in the Manifest file. Will that result in the permissions prompt to pop up at run time or is there anything else I need to do like add the getPermissionToRecordAudio() and onRequestPermissionsResult() code to MainActivity.java , etc? If so, where is the MainActivity.java in the Processing sketch documents? Do I have to use Android Studio for that? Pl let me know. Thanks.
Answers
@sonia===
if you are declaring "dangerous" permissions in the manifest there will be a popup at each time that the user launches the app
if you write code for asking on runtime the difference will be that you can "explain" why this permission is necessary and prevent the user (with a dialog) that some features will not run; in this case also you can add "alternative" to your app
in any case if >=API 23 the user can change his mind....
with P5 you cannot modify the MainActivity launcher class; you are in a fragment but you can write code for runtime permissions even in a fragment.
if you want to modify the MainActivity export your app and import it in AS or Eclipse.
I've already declared the dangerous permission in the manifest. But, that doesn't open up the pop-up. Instead, I've to manually go to settings and turn on the microphone permissions.
Secondly, I'm trying to add requestPermission() in the setup. That does prompt the user and also changes the microphone settings in the app. But, instead of starting to run, the app crashes. How do I get around it? Thanks.
Update: requestPermission("android.permission.RECORD_AUDIO") prompts the user, but once allowed crashes. However, after closing the app, when I open again on the phone, it works. So, when I run the app, it asks for permission and crashes. But, when i click the installed app on the phone, it works.
Does that mean that when the user downloads and installs the app, the prompt will ask and work? How will I know?
@sonia===
can you be more precise about:
your version of P5 android mode (because i have tested with 3, not with 4)
your target minSDK
your phone OS
knowing that the system permissions for API was changed since API 23:
from the android doc=
I need to figure out the code to write for run time permissions with record audio. For now, I just tried with requestPermission(...) and that simply brings about a pop up and pressing allow does open up the microphone. But, am not able to go beyond that. My code is this:
Once I request permission to record, how do I use the 'allow' press to dictate the audioRecord object? Its getting confusing now. Or should I use the conditional later here?
@sonia===
i thought that your problem was for permissions && seeing your previous posts i tested the code i have already used for that in eclipse, with some changes for P5; it runs in a standard way, asking the user to give permissions (in my snipet for RECORD_AUDIO, though i think that recording you have perhaps also to add WRITE_EXTERNAL_STORAGE); not any crash, neither at launch nor at resuming. Try the code below.
if now your question is about recording close this post and open another one.
CODE SNIPPET PERMISSIONS ON RUN TIME RECORD_AUDIO ADDED IN THE MANIFEST p5 .3.3, android mode 3 nexus 7 running 6.1
Thanks. I'll integrate this snippet with my source code and check.
My question is about mic permissions during run time. There is no recording here since the app is like a real time audio visualizer. So no storage of audio files and so on.
This is a fragment of the code:
Like I mentioned, I'm a novice. Pl bear with me. I integrated your snippet like this:
When I run the app, I get the same error: Unfortunately your app has stopped. I close it. But when I open the launched app again, it works and when I check the settings, the mic is on. Is my integrating wrong? Do I have to connect the permissions code with initializing the audioRecord object or something like that?
Phone has android version 6.0, android mode 4.0 in Processing. API Level - 23, according to https://stackoverflow.com/questions/3993924/get-android-api-level-of-phone-currently-running-my-application
Called the onRequestPermissionsResult() function with the conditional before doing my stuff in the draw() like this:
The last argument (int array grantResults) says 'variable does not exist'. Tried 0, grantResults[0], PERMISSION_GRANTED, etc., (as per developer.android site) not working. What should be passed as that int[] array?
@sonia===
Have you tested my snippet alone??? Does it works? Have you added the reor_audio permissionto your Manifest?
Now that i have understood what you re trying to do i ll' give a look to your code ASAP; yet, i am sure that the way you are asking for permissions in your last post is wrong.
@sonia===
i have tested your code + mine one that i have added.
as for permissions: not any problem, it works, asking the first time then no more asking (till the user changes his mind!)
as for record audio i cannot test (&& help to solve) because a) i dont see what is your import for fast fourier FFT b) there is not any method called getHigherP2() in your post
as for your error (last post) it is because you dont understand what this int Array is :an array made by the system when the user says "yes"; the request code can be any arbitrary int (i put 101, it could be 376!) - In your case as there is only 1 permission, the call back is at the [0] of the array, that s all...
Yes, tested your snippet alone and it works. Added record audio permissions to the manifest (otherwise the app will not run). I'm trying to figure out calling the function onRequestPermissionsResult(...). Here is the code for the method getHigherP2():
@sonia===
have you your own FFT class?
in setup() or in start() you check permissions state with checkSelfPermissions (see my boolean method); if "true"______nothing to do; else: "ask for some permission" with requestPermissions (my2° method)---- then: do nothing, the third method is a callBackfrom the second one
create a boolean "permissionOK" to false
when it' s true initialize your audioRecord, that s all...
Got it. Its working now. Thanks.
Meanwhile, I just came across your answer to view keyboard in android, that is, how to open a virtual keyboard on touch. Is there any inputmethodmanager to go to the next screen (featuring the main app) when a button named NEXT is touched on the first welcome page? Thanks.
@sonia===
for that open a new discussion tagged with android keyboard (it is for forums users when they are looking for some precise topic).
@sonia===
tested with your FFT class extending the abstract one: everything runs ok,though you draw nothing on screen...except the red text (change the textSize()).