Settings-Memory

存储设置

一:onCreate()方法

 @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        final Context context = getActivity();

        mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);//获得USB服务

        mStorageManager = StorageManager.from(context);
        mStorageManager.registerListener(mStorageListener);//存储管理者

        addPreferencesFromResource(R.xml.device_info_memory);//加载布局

        addCategory(StorageVolumePreferenceCategory.buildForInternal(context));

        final StorageVolume[] storageVolumes = mStorageManager.getVolumeList();
        for (StorageVolume volume : storageVolumes) {
            // add those storage volumes which are not emulated & allow UMS.
            // sometimes a storage drive like Mega SIM could carry two volumes,
            // with only one volume supported for UMS.
            if (!volume.isEmulated()) {
                // check if the colume is for UICC
                if (MediaFormat.isUiccStorage(volume, context) /*&& !volume.allowMassStorage()*/) {
                    // UICC volume that is not UMS enabled, shouldn't be shown on UI
                    Log.w(TAG, "UICC volume not UMS enabled. Not showing up on UI");
				continue;
					
                }
		
		if(!volume.allowMassStorage()){
			continue;
		}
		
                addCategory(StorageVolumePreferenceCategory.buildForPhysical(context, volume));
            }
        }

        setHasOptionsMenu(true);
    }
二:看XML文件
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
        android:title="@string/storage_settings_title">

<!-- Preference categories are dynamically created based on the list of available storage volumes -->

</PreferenceScreen>
三:分析<pre name="code" class="java"> addCategory(StorageVolumePreferenceCategory.buildForInternal(context));这个方法添加到fragment


 private void addCategory(StorageVolumePreferenceCategory category) {
        mCategories.add(category);///是个集合添加到这个集合中
        getPreferenceScreen().addPreference(category);//每个prefrence中添加
        category.init();初始化在StorageVolumePreferenceCategory这类中
    }
StorageVolumePreferenceCategory这个类:来初始化每个category

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值