lucasferreira / react-native-webview-android

Simple React Native Android module to use Android's WebView inside your app
356 stars 158 forks source link

could not get permissions for recording React-native version 0.21.0 #54

Closed niranjanbprajapati closed 7 years ago

niranjanbprajapati commented 8 years ago

I have loaded a url which records sound using mobile microphone. I also had set permission settings which is required by android Marshmallow 6.0 using the https://github.com/lucasferreira/react-native-android-permissions

But when i load the url it gives error on website.

could not get permissions for recording.

Is there any properties i need to set in the webview to provide access for recording, as i have already provided access permissions in android manifest as provided in the above example.

# Update code for permission in the react-native and android :

React-native code

The following code i have inserted on the link click which will open the webiview with the respective import code for permissions component.

import {checkPermission} from 'react-native-android-permissions';
import {requestPermission} from 'react-native-android-permissions';

onMMSLinkClick(url) {
        console.log('mms link click url :: ', url);
        //console.log('this.props :: ',this.props);
        checkPermission("android.permission.RECORD_AUDIO").then((result) => {
            console.log("checkPermission Recording Already Granted!", result);
            //console.log('checkPermission Recording granted results :: ', result);
        }, (result) => {
            console.log("checkPermission Recording Not Granted!", result);
            //console.log('checkPermission Recording Not Granted results :: ', result);
        });

        requestPermission("android.permission.RECORD_AUDIO").then((result) => {
            console.log("requestPermission Recording Granted!", result);
            // now you can set the listenner to watch the user geo location 
        }, (result) => {
            console.log("requestPermission Recording  Not Granted!",result);
            //console.log(result);
        });
        this.props.navigator.push({
            component: WebViewMMS,
            title: "MMS Practice",
            passProps: {
                url
            }
        });
    }

Android Code:

In settings.gradle file :

include ':RNWebView'
project(':RNWebView').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview-android/android')

include ':RNPermissionsModule'
project(':RNPermissionsModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-permissions/android')

In build.gradle file :

targetSdkVersion 23
compile project(':RNPermissionsModule')
compile project(':RNWebView')

In MainActivity.java File:

import com.burnweb.rnwebview.RNWebViewPackage;
import com.burnweb.rnpermissions.RNPermissionsPackage;

@Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new RNPermissionsPackage(),
            new RNWebViewPackage(),
);
}

@Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        RNPermissionsPackage.onRequestPermissionsResult(requestCode, permissions, grantResults); // very important event callback
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

If you need any other code. Please let me know.

lucasferreira commented 8 years ago

Hi @niranjanbprajapati

Can you show a little more about how are dealing with permissions?

Did put them in AndroidManifest.xml also? The dialog of permission request are prompted?

Are you testing in a real device?

niranjanbprajapati commented 8 years ago

I am testing in real device Nexus 5, also get the dialog of permission access for the first time when the app is installed. I selected Allow in the dialog. I have inserted permission in Manifest file also.

What can i do to help you understand my issue. Please let me know.

niranjanbprajapati commented 8 years ago

@lucasferreira can you please help me out, any idea where i am going wrong, in implementation of this.

lucasferreira commented 8 years ago

Hi @niranjanbprajapati

Did you fix this issue?

I've recommend you to update your React Native install to the latest (next) and try the native PermissionsAndroid implementations http://facebook.github.io/react-native/releases/next/docs/permissionsandroid.html

That can better them mine implementation ;)