Permission not working on andriod

var permissions = cordova.plugins.permissions;

                      var list = [
                        permissions.ACCESS_COARSE_LOCATION,
                        permissions.ACCESS_FINE_LOCATION,
                        permissions.ACCESS_BACKGROUND_LOCATION,
                      ];

                      permissions.hasPermission(list, function( status ){
                        if ( status.hasPermission ) {
                          console.log("Yes :D ");
                        }
                        else {
                          console.warn("No :( ");

                          permissions.requestPermission(permissions.ACCESS_COARSE_LOCATION, success, error);

                          permissions.requestPermission(permissions.ACCESS_FINE_LOCATION, success, error);

                          permissions.requestPermission(permissions.ACCESS_BACKGROUND_LOCATION, success, error);
 
                          function error() {
                            console.warn('Location is not turned on');
                          }
                           
                          function success( status ) {
                            if( !status.hasPermission ) error();
                          }
                        }
                      });

0:9993 Uncaught (in promise) Error: TypeError: Cannot read property 'permissions' of undefined

How do i access android permissions.

From my experience, the best way to detect what is not working in the App is debugging it, in the case of Android with the Chrome inspect. With this tool you can inspect your App like any other website.

To do so, follow these steps: https://stackoverflow.com/a/28967769/4208571

In the console, if you type “cordova” and hit enter, you will find the Cordova instance. Inside “cordova.plugins” you should have a property called “permissions”.
I don’t know what plugin you have implemented for the permissions but I recommend you use “[cordova-diagnostic-plugin] (GitHub - dpa99c/cordova-diagnostic-plugin: Cordova/Phonegap plugin to manage device settings)”

Here is a screenshot of inspecting an app:

I hope this helps you.

PS: This is an issue related to Cordova and the Pluging that you have implemented, not with Framework7. In any case, you should ask or open an issue in the plugin. This may be more effective for you to find the solution.

Regards, Fabricio.

Thanks for your reply.

But when i type cordova in the console i get

cordova.plugins
VM842:1 Uncaught ReferenceError: cordova is not defined
    at <anonymous>:1:1

What exists is a cordovaApp but does not have plugins option

Apparently cordova is not starting for some reason and that is why it does’t work.

Make sure the Cordova device ready fires and call the plugins after that event fires.

This is in the app.js in the init.

on: {
    init: function () {
      var f7 = this;
      if (f7.device.cordova) {
        // Init cordova APIs (see cordova-app.js)
        cordovaApp.init(f7);
      }
    },
    pageInit: function () {
      // check the local storage to see if the user has completed the onboarding process.

      const self = this;
      const app = self.$f7;
    },
  },

This is cordova-app.js

var cordovaApp = {
  f7: null,
  /*
  This method hides splashscreen after 2 seconds
  */
  handleSplashscreen: function() {
    var f7 = cordovaApp.f7;
    if (!window.navigator.splashscreen || f7.device.electron) return;
    setTimeout(() => {
      window.navigator.splashscreen.hide();
    }, 2000);
  },
  /*
  This method prevents back button tap to exit from app on android.
  In case there is an opened modal it will close that modal instead.
  In case there is a current view with navigation history, it will go back instead.
  */
  handleAndroidBackButton: function () {
    var f7 = cordovaApp.f7;
    const $ = f7.$;
    if (f7.device.electron) return;

    document.addEventListener('backbutton', function (e) {
      if ($('.actions-modal.modal-in').length) {
        f7.actions.close('.actions-modal.modal-in');
        e.preventDefault();
        return false;
      }
      if ($('.dialog.modal-in').length) {
        f7.dialog.close('.dialog.modal-in');
        e.preventDefault();
        return false;
      }
      if ($('.sheet-modal.modal-in').length) {
        f7.sheet.close('.sheet-modal.modal-in');
        e.preventDefault();
        return false;
      }
      if ($('.popover.modal-in').length) {
        f7.popover.close('.popover.modal-in');
        e.preventDefault();
        return false;
      }
      if ($('.popup.modal-in').length) {
        if ($('.popup.modal-in>.view').length) {
          const currentView = f7.views.get('.popup.modal-in>.view');
          if (currentView && currentView.router && currentView.router.history.length > 1) {
            currentView.router.back();
            e.preventDefault();
            return false;
          }
        }
        f7.popup.close('.popup.modal-in');
        e.preventDefault();
        return false;
      }
      if ($('.login-screen.modal-in').length) {
        f7.loginScreen.close('.login-screen.modal-in');
        e.preventDefault();
        return false;
      }

      if ($('.page-current .searchbar-enabled').length) {
        f7.searchbar.disable('.page-current .searchbar-enabled');
        e.preventDefault();
        return false;
      }

      if ($('.page-current .card-expandable.card-opened').length) {
        f7.card.close('.page-current .card-expandable.card-opened');
        e.preventDefault();
        return false;
      }

      const currentView = f7.views.current;
      if (currentView && currentView.router && currentView.router.history.length > 1) {
        currentView.router.back();
        e.preventDefault();
        return false;
      }

      if ($('.panel.panel-in').length) {
        f7.panel.close('.panel.panel-in');
        e.preventDefault();
        return false;
      }
    }, false);
  },
  onBackKeyDown: function () {

        if (app.view.main.router.currentRoute.name == 'index' || app.view.main.history.length == 1) {
            app.toast.create({
            text: 'Press back twice to exit app.',
            closeButton: true,
            closeButtonText: 'Close',
            closeButtonColor: 'red',
            closeTimeout: 2000,
            on: {
            closeButtonClick: function () {
            navigator.app.exitApp();
            e.preventDefault();
            },
            }
            }).open();
        } else {
        if ($$('.modal-in').length > 0) {
            app.popup.close();
            return false;
            } else if ($$('.card-opened').length > 0) {
            app.card.close('.card-expandable');
            //} else if ($$(’.panel-right’).length > 0) {
            // app.panel.close();
            } else {
            mainView.router.back();
            }
        }
        return true;
  },
  /*
  This method does the following:
    - provides cross-platform view "shrinking" on keyboard open/close
    - hides keyboard accessory bar for all inputs except where it required
  */
  handleKeyboard: function () {
    var f7 = cordovaApp.f7;
    if (!window.Keyboard || !window.Keyboard.shrinkView || f7.device.electron) return;
    var $ = f7.$;
    window.Keyboard.shrinkView(false);
    window.Keyboard.disableScrollingInShrinkView(true);
    window.Keyboard.hideFormAccessoryBar(true);
    window.addEventListener('keyboardWillShow', () => {
      f7.input.scrollIntoView(document.activeElement, 0, true, true);
    });
    window.addEventListener('keyboardDidShow', () => {
      f7.input.scrollIntoView(document.activeElement, 0, true, true);
    });
    window.addEventListener('keyboardDidHide', () => {
      if (document.activeElement && $(document.activeElement).parents('.messagebar').length) {
        return;
      }
      window.Keyboard.hideFormAccessoryBar(false);
    });
    window.addEventListener('keyboardHeightWillChange', (event) => {
      var keyboardHeight = event.keyboardHeight;
      if (keyboardHeight > 0) {
        // Keyboard is going to be opened
        document.body.style.height = `calc(100% - ${keyboardHeight}px)`;
        $('html').addClass('device-with-keyboard');
      } else {
        // Keyboard is going to be closed
        document.body.style.height = '';
        $('html').removeClass('device-with-keyboard');
      }

    });
    $(document).on('touchstart', 'input, textarea, select', function (e) {
      var nodeName = e.target.nodeName.toLowerCase();
      var type = e.target.type;
      var showForTypes = ['datetime-local', 'time', 'date', 'datetime'];
      if (nodeName === 'select' || showForTypes.indexOf(type) >= 0) {
        window.Keyboard.hideFormAccessoryBar(false);
      } else {
        window.Keyboard.hideFormAccessoryBar(true);
      }
    }, true);
  },
  handleGeolocation: function (params) {
      document.addEventListener("deviceready", onDeviceReady, false);

      function onDeviceReady() {
        console.log("navigator.geolocation works well");
      }
  },
  init: function (f7) {
    // Save f7 instance
    cordovaApp.f7 = f7;

    // Handle Android back button
    // cordovaApp.handleAndroidBackButton();

    // Handle Splash Screen
    cordovaApp.handleSplashscreen();

    // Handle Keyboard
    cordovaApp.handleKeyboard();

    // Handle Geolocation
    cordovaApp.handleGeolocation();

    // Handle Backbutton
    // cordovaApp.onBackKeyDown();
    
  },
};

Seems to be fine…

In your Terminal… can you type “cordova platform list” and “cordova plugin list” and show the results? (if you are using FWK7 CLI, add "framework7 " before “cordova” in root file).

Are you deploying in a physical device or emulator? Can you describe the steps you do to deploy your app?

λ framework7 cordova platform list
Error: ENOENT: no such file or directory, open 'C:\Users\ANCHOR WAY\.config\configstore\cordova-config.json'
Installed platforms:
  android 8.1.0
  ios 6.2.0
Available platforms:
  browser ^6.0.0
  electron ^1.0.0
  osx ^5.0.0
  windows ^7.0.0

Then the next command.

λ framework7 cordova plugin list
cordova-plugin-android-permissions 1.1.2 "Permissions"
cordova-plugin-geolocation 4.1.0 "Geolocation"
cordova-plugin-keyboard 1.2.0 "Keyboard"
cordova-plugin-splashscreen 6.0.0 "Splashscreen"
cordova-plugin-statusbar 2.4.3 "StatusBar"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova.plugins.diagnostic 6.0.3 "Diagnostic"
Error: ENOENT: no such file or directory, open 'C:\Users\ANCHOR WAY\.config\configstore\cordova-config.json'


   ╭──────────────────────────────────────╮
   │                                      │
   │   Update available 9.0.0 → 10.0.0    │
   │    Run npm i -g cordova to update    │
   │                                      │
   ╰──────────────────────────────────────╯

Are you deploying in a physical device or emulator?
ANS: physical device

First, you must have this code in your index.html:
<script type="text/javascript" src="cordova.js"></script>

Second, there are some plugins that don’t work correctly. For the permissions management, I suggest using the following plugin:

I use it myself and it works on most modern phones and Cordova versions.