0

I am currently having a problem on managing requests using geckoview. Android built in webview is not an option for me because the website I want to open is not compatible with chrome. It can be opened only using mozilla so geckoview is my alternative.

The problem I have is granting permission on using the microphone and recording audio. Because the website I am trying to open in geckoview records audio (voice Collection).

I'am new to android and geckoview thats why the guide I use is this project https://searchfox.org/mozilla-central/source/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java

I was able to show the request permission and accept it but it seems my application doesn't store the permission result. Currently I am trying my program to this website https://www.onlinemictest.com

This is my PermissionDelegate

private class ExamplePermissionDelegate implements GeckoSession.PermissionDelegate {
    public int androidPermissionRequestCode = 1;
    @Override
    public void onAndroidPermissionsRequest(GeckoSession session, String[] permissions, Callback callback)
    {
        if (ContextCompat.checkSelfPermission(MainActivity.this,
                Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED){
            Log.i(TAG, "Android Permission Needed");
            requestPermissions(permissions, androidPermissionRequestCode);
            callback = new ExamplePermissionCallback();
            callback.grant();
        }
        else{
            Log.i(TAG, "Android Permission Granted");
            callback.grant();
        }
    }
    @Override
    public void onContentPermissionRequest (GeckoSession session, String uri, int type, String access, Callback callback)
    {
        Log.i(TAG, "Content Permission Needed");
    }
    @Override
     public void onMediaPermissionRequest (GeckoSession session, String uri, MediaSource[] video, MediaSource[] audio, MediaCallback callback)
    {
        Log.i(TAG, "Media Permission Needed");   
        }
    }

and this is my PermissionDelegateCallback

 public class ExamplePermissionCallback implements GeckoSession.PermissionDelegate.Callback{
    @Override
    public void grant() {
        int permission = ContextCompat.checkSelfPermission(MainActivity.this,
                Manifest.permission.RECORD_AUDIO);
        if (permission != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(MainActivity.this,
                    new String[]{Manifest.permission.RECORD_AUDIO},
                    RECORD_REQUEST_CODE);}
    }
    @Override
    public void reject() {
    }
}

The result says 'Android Permission Granted' and after that, it shows the Log I put which is 'Media Permission Needed' and the website says 'Waiting for microphone'

I also checked the application on my phone and it already has the microphone permission.

Don Marti
  • 7
  • 2

1 Answers1

0

GeckoView has two levels of permissions:

  • The Android-level permission which Android grants to your app and you seem to be requesting correctly
  • The content-level permission which GeckoView grants to the specific web page and is not granted in your example.

In short, just because your app has permission to listen to the microphone, that doesn't mean that all web pages that you open in GeckoView will have access to the microphone.

When a page requests a media permission you get a onMediaPermission callback which you would need to accept using callback.grant, an example of this is here: https://searchfox.org/mozilla-central/rev/3483fb259b4edbe4594cfcc3911db97d5441b67d/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/BasicGeckoViewPrompt.java#927

The audio argument of onMediaPermission contains the list of all the audio sources (most likely you'll only have one, the microphone) which you can use to accept the prompt for the right audio source calling

@Override
public void onMediaPermissionRequest(
     GeckoSession session,
     String uri,
     MediaSource[] video,
     MediaSource[] audio,
     MediaCallback callback)
{
    // Find out which audio source is the microphone
    final int MICROPHONE_INDEX = ...;
    // Grant the request
    callback.grant(null, audio[MICROPHONE_INDEX]);
}

Note if you also need video, you can do the same thing with the video argument and the appropriate video source.

To figure out which one is the microphone you can use this snippet as example (look for SOURCE_MICROPHONE) https://searchfox.org/mozilla-central/source/mobile/android/geckoview_example/src/main/java/org/mozilla/geckoview_example/GeckoViewActivity.java#1201-1223

Agi Sferro
  • 626
  • 3
  • 12