{"__v":9,"_id":"573d83d9cf7be63200c5b174","category":{"__v":6,"_id":"55a589e30f354f0d00fd0312","pages":["55a590d080c8a30d00b32402","55a591c20f354f0d00fd0347","55a591c780c8a30d00b3240e","55a9172a27a17d210052524e","55a9222dc8bd450d000dd1a8","56d5d72da0b5600b000b1f7b"],"project":"559a61d2dbcfd20d00710b39","version":"559a61d2dbcfd20d00710b3c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-14T22:14:59.849Z","from_sync":false,"order":3,"slug":"android-sdk","title":"Android SDK"},"parentDoc":null,"project":"559a61d2dbcfd20d00710b39","user":"559a618bdbcfd20d00710b38","version":{"__v":23,"_id":"559a61d2dbcfd20d00710b3c","project":"559a61d2dbcfd20d00710b39","createdAt":"2015-07-06T11:09:06.510Z","releaseDate":"2015-07-06T11:09:06.510Z","categories":["559a61d3dbcfd20d00710b3d","55a589ddaaf9cf1900114dd0","55a589e30f354f0d00fd0312","55a589ea80c8a30d00b323cc","55a589f6aaf9cf1900114dd1","55a58d4e80c8a30d00b323e6","55a8e7a227a17d21005251a2","55a93098cf45e1390093f351","55afb085f202b12100cd9e83","55afb22e902fd51700f5f8bf","55afb260902fd51700f5f8c2","55afb28ec8a85321007a5462","55afb294f202b12100cd9e95","55afb29b902fd51700f5f8c5","55afb2a1c8a85321007a5463","55afb2a7902fd51700f5f8c7","55afb2ad902fd51700f5f8c8","55afb2b5902fd51700f5f8ca","55b74b2131bccb190081bedc","55bb441b54f9640d006e6cf2","565711085cb2420d00d70071","5681681330018c0d006bf7ff","588f38b5923d610f00c72dad"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-19T09:14:01.099Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":5,"body":"Starting from **Android 6.0**, there are some permissions that are considered *dangerous*. All the permissions that fall into this category **are no longer requested at install time, but at Run Time.**\n\n##Android Lollipop and lower\n\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/utGBMUxUSWabJudw5kv6_lollipop-permissions.jpg\",\n        \"lollipop-permissions.jpg\",\n        \"630\",\n        \"1120\",\n        \"#6d944b\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n##Android Marshmallow and greater\n\n\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/RZuk8nGtQj6YGS9uik0c_marshmallow-permissions.jpg\",\n        \"marshmallow-permissions.jpg\",\n        \"630\",\n        \"1120\",\n        \"#4aa096\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Requesting permissions at runtime.\"\n}\n[/block]\nMOCA SDK requires the `ACCESS_FINE_LOCATION` permission for **bluetooth** scanning, **location tracking** and **geofencing**. Request this permission in your Main Activity this way:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"final int REQUEST_PERMISSION_GEO = 101;        \\nfinal String permissionStr = android.Manifest.permission.ACCESS_FINE_LOCATION;\\n\\n\\n:::at:::TargetApi(Build.VERSION_CODES.M)\\nprivate void requestMocaPermissions() {\\n  final int permStatus = ContextCompat.checkSelfPermission(this, FINE_LOCATION_PERMISSION);\\n  if (permStatus != PackageManager.PERMISSION_GRANTED) {\\n    if (shouldShowRequestPermissionRationale(FINE_LOCATION_PERMISSION)) {\\n\\n      AlertDialog.Builder builder = new AlertDialog.Builder(this);\\n\\n      builder.setMessage(R.string.LOCATION_PERMISSION_DESCRIPTION)\\n        .setTitle(R.string.APP_SHORT_NAME)\\n        .setNeutralButton(R.string.OK_TEXT, new DialogInterface.OnClickListener() {\\n\\n          public void onClick(DialogInterface dialog, int which) {\\n            requestPermissions(new String[]{FINE_LOCATION_PERMISSION},\\n                               REQUEST_PERMISSION_GEO);\\n          }\\n\\n        }).show();\\n\\n    } else {\\n      // No explanation needed, we can request the permission.\\n      requestPermissions(new String[]{FINE_LOCATION_PERMISSION},\\n                         REQUEST_PERMISSION_GEO);\\n    }\\n  }\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Permission Request example\"\n    }\n  ]\n}\n[/block]\nOnce the user allows or denies the permission, Android will send you this information using the `onRequestPermissionsResult` callback. Below you will find an example of how to implement this method, and how to initialize the permission-affected MOCA Services:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"/**\\n     * Callback received when a permissions request has been completed.\\n     */\\n    @Override\\n    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,\\n                                           @NonNull int[] grantResults) {\\n\\n        if((requestCode == REQUEST_PERMISSION_GEO)\\n                && (permissions[0].equals(FINE_LOCATION_PERMISSION))\\n                && (grantResults[0] == PackageManager.PERMISSION_GRANTED)){\\n            if(MOCA.initialized()){\\n                MOCA.setProximityEnabled(true);\\n                MOCA.setGeoTrackingEnabled(true);\\n            }\\n        }\\n        else{\\n            Log.e(\\\"MOCA\\\", \\\"Location permission denied by the user.\\\");\\n        }\\n    }\",\n      \"language\": \"java\",\n      \"name\": \"Permission request callback\"\n    }\n  ]\n}\n[/block]\nLearn more about [requesting permissions at Run Time.](https://developer.android.com/training/permissions/requesting.html) (external link).","excerpt":"","slug":"android-60-permissions","type":"basic","title":"Android 6.0+ permissions"}

Android 6.0+ permissions


Starting from **Android 6.0**, there are some permissions that are considered *dangerous*. All the permissions that fall into this category **are no longer requested at install time, but at Run Time.** ##Android Lollipop and lower [block:image] { "images": [ { "image": [ "https://files.readme.io/utGBMUxUSWabJudw5kv6_lollipop-permissions.jpg", "lollipop-permissions.jpg", "630", "1120", "#6d944b", "" ] } ] } [/block] ##Android Marshmallow and greater [block:image] { "images": [ { "image": [ "https://files.readme.io/RZuk8nGtQj6YGS9uik0c_marshmallow-permissions.jpg", "marshmallow-permissions.jpg", "630", "1120", "#4aa096", "" ] } ] } [/block] [block:api-header] { "type": "basic", "title": "Requesting permissions at runtime." } [/block] MOCA SDK requires the `ACCESS_FINE_LOCATION` permission for **bluetooth** scanning, **location tracking** and **geofencing**. Request this permission in your Main Activity this way: [block:code] { "codes": [ { "code": "final int REQUEST_PERMISSION_GEO = 101; \nfinal String permissionStr = android.Manifest.permission.ACCESS_FINE_LOCATION;\n\n\n@TargetApi(Build.VERSION_CODES.M)\nprivate void requestMocaPermissions() {\n final int permStatus = ContextCompat.checkSelfPermission(this, FINE_LOCATION_PERMISSION);\n if (permStatus != PackageManager.PERMISSION_GRANTED) {\n if (shouldShowRequestPermissionRationale(FINE_LOCATION_PERMISSION)) {\n\n AlertDialog.Builder builder = new AlertDialog.Builder(this);\n\n builder.setMessage(R.string.LOCATION_PERMISSION_DESCRIPTION)\n .setTitle(R.string.APP_SHORT_NAME)\n .setNeutralButton(R.string.OK_TEXT, new DialogInterface.OnClickListener() {\n\n public void onClick(DialogInterface dialog, int which) {\n requestPermissions(new String[]{FINE_LOCATION_PERMISSION},\n REQUEST_PERMISSION_GEO);\n }\n\n }).show();\n\n } else {\n // No explanation needed, we can request the permission.\n requestPermissions(new String[]{FINE_LOCATION_PERMISSION},\n REQUEST_PERMISSION_GEO);\n }\n }\n}", "language": "java", "name": "Permission Request example" } ] } [/block] Once the user allows or denies the permission, Android will send you this information using the `onRequestPermissionsResult` callback. Below you will find an example of how to implement this method, and how to initialize the permission-affected MOCA Services: [block:code] { "codes": [ { "code": "/**\n * Callback received when a permissions request has been completed.\n */\n @Override\n public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,\n @NonNull int[] grantResults) {\n\n if((requestCode == REQUEST_PERMISSION_GEO)\n && (permissions[0].equals(FINE_LOCATION_PERMISSION))\n && (grantResults[0] == PackageManager.PERMISSION_GRANTED)){\n if(MOCA.initialized()){\n MOCA.setProximityEnabled(true);\n MOCA.setGeoTrackingEnabled(true);\n }\n }\n else{\n Log.e(\"MOCA\", \"Location permission denied by the user.\");\n }\n }", "language": "java", "name": "Permission request callback" } ] } [/block] Learn more about [requesting permissions at Run Time.](https://developer.android.com/training/permissions/requesting.html) (external link).