Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Grant Permission at Android 21 #1447

Closed
2 tasks done
GitMustafaAksoy opened this issue Nov 30, 2022 · 8 comments
Closed
2 tasks done

Cannot Grant Permission at Android 21 #1447

GitMustafaAksoy opened this issue Nov 30, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@GitMustafaAksoy
Copy link

GitMustafaAksoy commented Nov 30, 2022

  • I have read the Getting Started section
  • I have already searched for the same problem

Environment

Technology Version
Flutter version 3.3.8
Plugin version any
Android version Api 21
iOS version
macOS version
Xcode version

Device information:
Asus k012_2 SM | Samsung SM-N9000Q

Description

Expected behavior:
Same code for WEB RTC works fine at Android Api level 23 and greater levels, but at api level 21 the devices cannot grant microphone permission.
Current behavior:
The devices cannot grant microphone permission at api level 21.

Steps to reproduce

import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:permission_handler/permission_handler.dart';


Future main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Permission.camera.request();
  await Permission.microphone.request();

  if (Platform.isAndroid) {
    await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
  }

  runApp(MyApp());
}


class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MainPage(),
    );
  }
}


class MainPage extends StatefulWidget {
  const MainPage({Key? key}) : super(key: key);

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
      children: [
          ElevatedButton(
            onPressed: () {
              Navigator.push(context, MaterialPageRoute(builder: (context) => CallApp()));
            },
            child: Text('call'),
          )
      ],
    ),
        ));
  }
}

class CallApp extends StatefulWidget {
  @override
  _CallAppState createState() => new _CallAppState();
}

class _CallAppState extends State<CallApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: InAppWebViewPage()
    );
  }
}

class InAppWebViewPage extends StatefulWidget {
  @override
  _InAppWebViewPageState createState() => new _InAppWebViewPageState();
}

class _InAppWebViewPageState extends State<InAppWebViewPage> {
  late InAppWebViewController _webViewController;


  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: const Text("InAppWebView")
        ),
        body: Container(
            child: Column(children: <Widget>[
              Expanded(
                child: Container(
                  child: InAppWebView(
                      initialData: InAppWebViewInitialData(data: '''
<html>                                   
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
</head>
  <body>
      <script type="text/javascript" src="test.com.js"></script>
  <script type="text/javascript">
      startScript({
        client_data: {PhoneNumber: "XXXXXXXXXXXX", id: "XXXX"}});</script>
  </body>
  </html>'''),

                      initialOptions: InAppWebViewGroupOptions(
                        android: AndroidInAppWebViewOptions(hardwareAcceleration: false,
                        ),
                        crossPlatform: InAppWebViewOptions(
                          mediaPlaybackRequiresUserGesture: false,
                          javaScriptEnabled: true,
                          allowFileAccessFromFileURLs: true,
                          javaScriptCanOpenWindowsAutomatically: true,
                          allowUniversalAccessFromFileURLs: true,
                        ),
                      ), onWebViewCreated: (InAppWebViewController controller) {
                        _webViewController = controller;

                      },
                      androidOnPermissionRequest: (InAppWebViewController controller, String origin, List<String> resources) async {
                        return PermissionRequestResponse(resources: resources, action: PermissionRequestResponseAction.GRANT);
                      }
                  ),
                ),
              ),
            ])
        )
    );
  }
}
@GitMustafaAksoy GitMustafaAksoy added the bug Something isn't working label Nov 30, 2022
@github-actions
Copy link

👋 @GitMustafaAksoy

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

@pichillilorenzo
Copy link
Owner

On Android, onPermissionRequest for plugin version 6 and androidOnPermissionRequest for plugin version 5 are available only starting from Android SDK 23+.
Check the API Reference:

@GitMustafaAksoy
Copy link
Author

GitMustafaAksoy commented Nov 30, 2022

I want to be sure what I understand, could you please clarify that for me? In native development, according to this information "onPermissionRequest method" is avaible for api 21+, but not avaible for flutter_inappwebview api 23<=? So I need native development.

@pichillilorenzo
Copy link
Owner

Ah wow, for some strange reason, the Android Studio IDE was telling me it was 23 and not 21.
Well, I will release a new version 6 and new version 5 with that fix

@GitMustafaAksoy
Copy link
Author

GitMustafaAksoy commented Nov 30, 2022

Thank you in advance for your help, I will be looking forward to new release.

@pichillilorenzo pichillilorenzo changed the title Cannot Grant Microphone Permission at Android 21 Cannot Grant Permission at Android 21 Nov 30, 2022
pichillilorenzo added a commit that referenced this issue Nov 30, 2022
@pichillilorenzo
Copy link
Owner

Released new version 6.0.0-beta.19 and new version 5.7.2+1.

@GitMustafaAksoy
Copy link
Author

Thank you for your time, the fastest release ever in the world :) I’m going to test it in api 21 devices, tomorrow.

@GitMustafaAksoy
Copy link
Author

The release has been tested in the devices, and works well. Thank you again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants