Search code examples
ionic-frameworkcordova-pluginsandroid-permissions

Android 6 Permission denied for Reading SMS?


Hi I am developing ionic application which is reading users sms , in android 6 mobile phones It does not read SMS , Instead it shows the error , Permission Denied, How to Fix it thanks in Advance ?

I am Using

  • cordova-plugin-sms

Solution

    • install this plugin cordova plugin add [email protected]
    • Just add this code into ionic.Platform.ready it will ask one time permission ..

      var permissions = window.plugins.permissions;
      permissions.hasPermission(checkPermissionCallback, null, permissions.R);
      
      function checkPermissionCallback(status) {
        if(!status.hasPermission) {
          var errorCallback = function() {
            ionic.Platform.exitApp();
      
          }
      
          permissions.requestPermission(function(status) {
      
            if( !status.hasPermission ) errorCallback();
          }, errorCallback, permissions.READ_SMS);
        }
      }