导入相关类以使用Asset存储能力:
import android.os.Bundle; import android.content.Context; import com.huawei.android.util.NoExtAPIException; import com.huawei.security.hwassetmanager.HwAssetManager;
HwAssetManager assetManager = null;
try {
assetManager = HwAssetManager.getInstance();
} catch (NoExtAPIException e) {
// handle the exception...
} Bundle bundle = new Bundle();
// 可配置BUNDLE_ASSETTYPE,默认为HwAssetManager.ASSET_TYPE_USERNAME_PASSWORD
bundle.putInt(HwAssetManager.BUNDLE_ASSETTYPE, HwAssetManager.ASSET_TYPE_CREDIT_CARD);
bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag");
bundle.putString(HwAssetManager.BUNDLE_BATCHASSET, "demo_batchasset");
bundle.putString(HwAssetManager.BUNDLE_AEADASSET, "demo_aeadasset");
bundle.putString(HwAssetManager.BUNDLE_EXTINFO, "demo_extinfo");
try {
HwAssetManager.AssetResult result = assetManager.assetInsert(context, bundle); // context is ready.
} catch (NoExtAPIException e) {
// handle the exception...
}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...
}Bundle bundle = new Bundle();
bundle.putString(HwAssetManager.BUNDLE_ASSETHANDLE, "demo_assethandle");
bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag");
bundle.putString(HwAssetManager.BUNDLE_BATCHASSET, "demo_batchasset");
bundle.putString(HwAssetManager.BUNDLE_AEADASSET, "demo_aeadasset");
bundle.putString(HwAssetManager.BUNDLE_EXTINFO, "demo_extinfo");
try {
HwAssetManager.AssetResult result = assetManager.assetUpdate(context, bundle); // context is ready.
} catch (NoExtAPIException e) {
// handle the exception...
}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...
}Bundle bundle = new Bundle();
bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag"); // 配置应用包名等信息,不指定则查询所有Asset数据
bundle.putInt(HwAssetManager.BUNDLE_SELECT_MODE, HwAssetManager.SELECT_FROM_BEGIN); // 配置查询模式为从头查询,一次最多10条
try {
HwAssetManager.AssetResult result = assetManager.assetSelect(context, bundle); // context is ready.
} catch (NoExtAPIException e) {
// handle the exception...
}Bundle bundle = new Bundle();
bundle.putString(HwAssetManager.BUNDLE_APPTAG, "demo_apptag"); // 配置应用包名等信息,不指定则查询所有Asset数据
bundle.putInt(HwAssetManager.BUNDLE_SELECT_MODE, HwAssetManager.SELECT_CONTINUE); // 配置查询模式为继续查询,一次最多10条
try {
HwAssetManager.AssetResult result = assetManager.assetSelect(context, bundle); // context is ready.
} catch (NoExtAPIException e) {
// handle the exception...
}例如:查询并删除一条用户短敏感数据。
HwAssetManager assetManager = null;
try {
assetManager = HwAssetManager.getInstance();
} catch (NoExtAPIException e) {
// handle the exception...
} 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...
} 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...
}