目录

开发步骤

使用前准备

导入相关类以使用Asset存储能力:

import android.os.Bundle;
import android.content.Context;
import com.huawei.android.util.NoExtAPIException;
import com.huawei.security.hwassetmanager.HwAssetManager;

接口使用示例

使用场景代码前需获取Asset存储实例:
HwAssetManager assetManager = null; 
try { 
    assetManager = HwAssetManager.getInstance(); 
} catch (NoExtAPIException e) { 
    // handle the exception... 
}

场景介绍

场景举例实现

例如:查询并删除一条用户短敏感数据。

  1. 导入使用Asset存储能力的相关类。
  2. 调用HwAssetManager的getInstance方法获取Asset存储实例。

    HwAssetManager assetManager = null; 
    try { 
        assetManager = HwAssetManager.getInstance(); 
    } catch (NoExtAPIException e) { 
        // handle the exception... 
    }

  3. 调用HwAssetManager的assetSelect方法查询一条用户短敏感数据记录。

    Bundle bundle = new Bundle(); 
    bundle.putString(HwAssetManager.BUNDLE_ASSETHANDLE, "demo_assethandle"); 
    bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag"); 
    bundle.putInt(HwAssetManager.BUNDLE_SELECT_MODE, HwAssetManager.SELECT_ONCE); 
    try { 
        HwAssetManager.AssetResult result = assetManager.assetSelect(context, bundle); // context is ready. 
    } catch (NoExtAPIException e) { 
        // handle the exception... 
    }

  4. 调用HwAssetManager的assetDelete方法删除一条用户短敏感数据记录。

    Bundle bundle = new Bundle(); 
    bundle.putString(HwAssetManager.BUNDLE_ASSETHANDLE, "demo_assethandle"); 
    bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag"); 
    try { 
        HwAssetManager.AssetResult result = assetManager.assetDelete(context, bundle); // context is ready. 
    } catch (NoExtAPIException e) { 
        // handle the exception... 
    }

  5. 查询数据库中记录是否已经被删除检验操作结果。