We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

Canceling Authorization

Content overview

To improve privacy security, your app should allow users to cancel authorization after Obtaining User Authorization.

NOTE
  1. Methods for canceling authorization described in this section are not applicable for countries or regions that only support access through the SDK for Android, like Russia. For details about how to cancel authorization for these countries or regions, please refer to Canceling Authorization.
  2. Calling cancelAuthorization(boolean deleteData) will cancel all scopes granted to your app. If you want to cancel certain scopes, call cancelAuthorization(String appId, List<String> scopes) instead.
  3. Canceling authorization can cancel the authorization that a user once granted to the app. After the authorization is canceled, error code 2002 will be reported when you call the API for silent sign-in. When the user signs in again, your app will display the authorization screen, prompting the user to reauthorize.
  4. Before the function to cancel authorization is available in your app, users can manually cancel the authorization to Health Service Kit in the following ways:
    • Go to Settings > HUAWEI ID > Privacy center > Control account access. Select the app for which you want to cancel the authorization, and then cancel the authorization.
    • Open the Huawei Health app, and go to Me > Privacy management > Data sharing and authorization. Select the app for which you want to cancel the authorization, and then cancel the authorization.

Development Procedure

The key steps for developing the function of canceling authorization from your app are as follows:

  1. Configure an entry to allow a user to cancel authorization granted to your app. (Implement this step by yourself.)
  2. Call the cancelAuthorization(boolean deleteData) method and process the returned result.

    // Log tag
    private static final String TAG = "HealthKitConsents";
    
    public void cancelAuthorization(View view) {
        // 1. Obtain a ConsentsController object.
        // Note that this refers to an Activity object.
        ConsentsController mConsentsController = HuaweiHiHealth.getConsentsController(this);
        // 2. Specify whether to delete user data. true if so; false otherwise.
        boolean clearUserData = true;
        // 3. Cancel all authorization granted to the app and delete user data.
        Task<Void> task = mConsentsController.cancelAuthorization(clearUserData);
        task.addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                Log.i(TAG, "cancelAuthorization success");
                if(clearUserData){
                    Log.i(TAG, "clearUserData success");
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                Log.e(TAG, "cancelAuthorization exception");
            }
        });
    }

Search
Enter a keyword.