Skip to content
This repository has been archived by the owner on May 23, 2023. It is now read-only.

Testing Android API 23 Permissions

Juan Pablo Cuevas Sclopis edited this page Jul 20, 2017 · 4 revisions

You can test Android 6 permissions with the following simple implementation

Start a new ionic project and add this plugin

ionic start testing blank
cd testing
ionic cordova plugin add cordova-plugin-sim

Add new file: www/js/MainCtrl.js

angular.module('starter')
.controller('MainCtrl', ['$scope', '$timeout', function($scope, $timeout) {
  ionic.Platform.ready(function() {
    console.log('ionic.Platform.ready');
    window.plugins.sim.getSimInfo(
      function(r) { $scope.out = r; $scope.$apply(); console.log(r); },
      function(r) { $scope.out = r; $scope.$apply(); console.log(r); }
    );
    window.plugins.sim.hasReadPermission(
      function(r) { $scope.out2 = r; $scope.$apply(); console.log(r); },
      function(r) { $scope.out2 = r; $scope.$apply(); console.log(r); }
    );
    $timeout(function() {
      window.plugins.sim.requestReadPermission();
    }, 5000);
    $timeout(function() {
      window.plugins.sim.getSimInfo(
        function(r) { $scope.out3 = r; $scope.$apply(); console.log(r); },
        function(r) { $scope.out3 = r; $scope.$apply(); console.log(r); }
      );
      window.plugins.sim.hasReadPermission(
        function(r) { $scope.out4 = r; $scope.$apply(); console.log(r); },
        function(r) { $scope.out4 = r; $scope.$apply(); console.log(r); }
      );
    }, 10000);
  });

}]);

Replace this file: www/index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    <meta http-equiv="Content-Security-Policy">
    <title>Cordova Sim Permission Test</title>
    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="cordova.js"></script>
    <script src="js/app.js"></script>
    <script src="js/MainCtrl.js"></script>
  </head>
  <body ng-app="starter" ng-controller="MainCtrl">
    <ion-pane>
      <ion-header-bar class="bar-stable">
        <h1 class="title">Cordova Sim Permission Test</h1>
      </ion-header-bar>
      <ion-content class="padding">
        <p>Before permission request:</p>
        <p>Data: {{out}}</p>
        <p>Permission: {{out2}}</p>
        <p>After permission request:</p>
        <p>Data: {{out3}}</p>
        <p>Permission: {{out4}}</p>
      </ion-content>
    </ion-pane>
  </body>
</html>

build and run the application in your phone

ionic platform add android
ionic build android
ionic run android
Clone this wiki locally