格式化内置T卡和外置T卡
发布日期:2021-05-16 17:47:32 浏览次数:13 分类:精选文章

本文共 2125 字,大约阅读时间需要 7 分钟。

T卡格式化处理

内置T卡格式化

内置T卡的格式化过程主要由com.android.settings.deviceinfo.PrivateVolumeFormat类负责。该类通过StorageManager获取存储管理服务,并结合VolumeInfo中的VolumeId参数初始化相关UI组件。具体实现步骤如下:

  • 使用StorageManager获取存储管理服务
  • 根据VolumeInfo.EXTRA_VOLUME_ID参数获取具体的体积ID
  • 加载并初始化storage_internal_format布局文件
  • 提取并设置布局中的文本内容
  • 定义确认操作的点击事件处理逻辑
  • 代码片段:

    final StorageManager storage = getActivity().getSystemService(StorageManager.class);final String volumeId = getArguments().getString(VolumeInfo.EXTRA_VOLUME_ID);final View view = inflater.inflate(R.layout.storage_internal_format, container, false);final TextView body = (TextView) view.findViewById(R.id.body);final Button confirm = (Button) view.findViewById(R.id.confirm);mVolume = storage.findVolumeById(volumeId);if (mVolume == null) {    getActivity().finish();} else {    mDisk = storage.findDiskById(mVolume.getDiskId());    body.setText(TextUtils.expandTemplate(getText(R.string.storage_internal_format_details),            mDisk.getDescription()));}confirm.setOnClickListener(mConfirmListener);

    外部T卡格式化

    外部T卡的格式化处理主要由Settings$StorageDashboardActivityStorageWizardFormatConfirm类负责。具体流程如下:

  • Settings$StorageDashboardActivity中根据用户选择的格式化类型(公用卷或私用卷)启动StorageWizardFormatConfirm活动
  • StorageWizardFormatConfirm类通过传递DiskInfo.EXTRA_DISK_IDStorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE参数区分公用卷和私用卷格式化需求
  • 根据不同的格式化需求启动相应的格式化工具(如StorageWizardFormatPublicStorageWizardFormatPrivate
  • 调用storage.partitionPublicstorage.partitionInternal接口执行具体格式化操作
  • 代码片段:

    } else if (pref == mFormatPublic) {    // 外部T卡    final Intent intent = new Intent(context, StorageWizardFormatConfirm.class);    intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());    intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, false);    startActivity(intent);} else if (pref == mFormatPrivate) {    // 内部T卡    final Intent intent = new Intent(context, StorageWizardFormatConfirm.class);    intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());    intent.putExtra(StorageWizardFormatConfirm.EXTRA_FORMAT_PRIVATE, true);    startActivity(intent);}

    总结

    内置T卡和外部T卡的格式化处理虽然目标不同,但都依赖于StorageManager服务的核心功能来实现。通过合理的UI设计和逻辑分离,确保了用户能够根据实际需求选择适合的格式化方式,同时保证了系统的稳定性和用户体验。

    上一篇:android开机动画到桌面黑屏解决办法
    下一篇:Android中有四种引用类型及GC回收区别

    发表评论

    最新留言

    关注你微信了!
    [***.104.42.241]2025年05月01日 04时48分36秒