HealthPermissionManager
overviewpackageclasstreedeprecatedindex com samsung android sdk healthdata class healthpermissionmanager java lang object com samsung android sdk healthdata healthpermissionmanager public class healthpermissionmanager extends object this class requests permission to read or write health data for the specific health data type note, healthconstants healthdocument can be accessed with the instant permission see acquring instant data permission requesting permission an application can access health data only if the user consents permission for data access can be requested by each data type and the permission type read or write public class mainactivity extends activity { // the state of connection private healthdatastore mstore; set<permissionkey> mkeys = new hashset<permissionkey> ; private static final string app_tag = "myapp"; public void requestpermission { // acquire permission healthpermissionmanager pmsmanager = new healthpermissionmanager mstore ; mkeys add new permissionkey exercise health_data_type, permissiontype read ; mkeys add new permissionkey exercise health_data_type, permissiontype write ; mkeys add new permissionkey stepdailytrend health_data_type, permissiontype read ; try { pmsmanager requestpermissions mkeys, mainactivity this setresultlistener mpermissionlistener ; } catch exception e { log d app_tag, "requestpermissions fails" ; } } if requestpermissions succeeds, the permission ui is popped up on the device the user can check and allow each data type's permission with scrolling down if the user allows permission items on the permission ui and select "done", its result is sent to permissionresult and you can check whether the user allows the data access or not private final healthresultholder resultlistener<permissionresult> mpermissionlistener = new healthresultholder resultlistener<permissionresult> { @override public void onresult permissionresult result { map<permissionkey, boolean> resultmap = result getresultmap ; if resultmap values contains boolean false { log d app_tag, "all required permissions are not granted " ; } else { log d app_tag, "all required permissions are granted " ; //access health data } } }; } specifying permission in manifest not only calling permission related apis, but specifying permission in the manifest file is required the declared permission items in the application's manifest are shown on "samsung health > settings > data permissions > [yourapp]" manifest below contains two data permissions to read and one data permission to write health data use the semicolon ; to declare multiple data types <manifest > <application > <meta-data android name="com samsung android health permission read" android value="com samsung health exercise;com samsung shealth step_daily_trend"/> <meta-data android name="com samsung android health permission write" android value="com samsung health exercise"/> </application> </manifest> the constant value of the required data type can be checked as shown below find its health_data_type in api reference e g if the data type is healthconstants exercise, you'll meet the following description use the constant value, "com samsung health exercise", for a permission declaration in your app's manifest file guidelines for permission request acquiring permission from the user is essential to access health data but too frequent requests of permission can annoy the user here are guidelines that help you to find a solution for the permission request permission needs to be requested in the following cases when your application connects to samsung health at the first time if there is a menu that connects to samsung health in your application and the user selects it and avoid requesting permission in the following cases when your application goes on the background frequent requests of permission until the user grants an occasional nudge is fine see the privacy section of programming guide for more information since 1 0 0 nested class summary nested classes modifier and type class and description static class healthpermissionmanager permissionkey this class represents the permission key which consists of a health data type and a permission type static class healthpermissionmanager permissionresult this class represents the result of requestpermissions set, activity static class healthpermissionmanager permissiontype this enum defines the permission type to read or write health data constructor summary constructors constructor and description healthpermissionmanager healthdatastore store constructs and initializes an instance of healthpermissionmanager method summary all methods instance methods concrete methods deprecated methods modifier and type method and description map<healthpermissionmanager permissionkey,boolean> ispermissionacquired set<healthpermissionmanager permissionkey> permissionkeys checks whether the specified permissions are acquired healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys deprecated use requestpermissions set, activity instead of it healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys, activity activity requests permissions through the permission ui on the given activity constructor detail healthpermissionmanager public healthpermissionmanager healthdatastore store constructs and initializes an instance of healthpermissionmanager parameters store - the successful connection to the health data store since 1 0 0 method detail requestpermissions public healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys deprecated use requestpermissions set, activity instead of it requests permissions through the permission ui if it is called, the permission ui is shown to the user avoid calling this method frequently refer to its guidelines parameters permissionkeys - the set of required permission keys returns the permission result that resolves to the requested permission keys throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 0 0 requestpermissions public healthresultholder<healthpermissionmanager permissionresult> requestpermissions set<healthpermissionmanager permissionkey> permissionkeys, activity activity requests permissions through the permission ui on the given activity if it is called, the permission ui is shown to the user avoid calling this method frequently refer to its guidelines parameters permissionkeys - the set of required permission keys activity - the activity that pop up the permission ui returns the permission result that resolves to the requested permission keys throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 2 0 ispermissionacquired public map<healthpermissionmanager permissionkey,boolean> ispermissionacquired set<healthpermissionmanager permissionkey> permissionkeys checks whether the specified permissions are acquired parameters permissionkeys - the set of permission keys to check acquisition returns the result map representing whether the specified permissions are acquired the permission state for the specific permission key can be retrieved by map get object as the following example public class healthpermissionmanagerexample { // the state of connection private healthdatastore mstore; private static final string app_tag = "myapp"; private void checkpermissions { healthpermissionmanager pmsmanager = new healthpermissionmanager mstore ; set<healthpermissionmanager permissionkey> keys = new hashset<healthpermissionmanager permissionkey> ; healthpermissionmanager permissionkey key1 = new healthpermissionmanager permissionkey healthconstants bloodglucose health_data_type, healthpermissionmanager permissiontype read ; keys add key1 ; healthpermissionmanager permissionkey key2 = new healthpermissionmanager permissionkey healthconstants bloodpressure health_data_type, healthpermissionmanager permissiontype read ; keys add key2 ; try { map resultmap = pmsmanager ispermissionacquired keys ; if resultmap get key1 == boolean true { log d app_tag, "you can read the blood glucose data type " ; } else { log d app_tag, "there is no permission to read the blood glucose data type " ; } if resultmap get key2 == boolean true { log d app_tag, "you can read the blood pressure data type " ; } else { log d app_tag, "there is no permission to read the blood pressure data type " ; } } catch exception e { log d app_tag, "check the connection " ; } } } throws illegalargumentexception - if the permissionkeys is invalid illegalstateexception - if the connection to the health data store is invalid or a remote-invocation error occurs on the connection since 1 0 0