java读取mtp,Java MtpConstants類代碼示例

import android.mtp.MtpConstants; //導入依賴的package包/類

private void indexDevice() throws IndexingException {

synchronized (MtpDeviceIndex.this) {

mProgress = Progress.Started;

}

mBucketsTemp = new HashMap();

for (int storageId : mDevice.getStorageIds()) {

if (mDevice != getDevice()) throw new IndexingException();

Stack pendingDirectories = new Stack();

pendingDirectories.add(0xFFFFFFFF); // start at the root of the device

while (!pendingDirectories.isEmpty()) {

if (mDevice != getDevice()) throw new IndexingException();

int dirHandle = pendingDirectories.pop();

for (int objectHandle : mDevice.getObjectHandles(storageId, 0, dirHandle)) {

MtpObjectInfo objectInfo = mDevice.getObjectInfo(objectHandle);

if (objectInfo == null) throw new IndexingException();

int format = objectInfo.getFormat();

if (format == MtpConstants.FORMAT_ASSOCIATION) {

pendingDirectories.add(objectHandle);

} else if (SUPPORTED_IMAGE_FORMATS.contains(format)

|| SUPPORTED_VIDEO_FORMATS.contains(format)) {

addObject(objectInfo);

}

}

}

}

Collection values = mBucketsTemp.values();

mBucketsTemp = null;

mBuckets = values.toArray(new DateBucket[values.size()]);

values = null;

synchronized (MtpDeviceIndex.this) {

mProgress = Progress.Sorting;

if (mProgressListener != null) {

mProgressListener.onSorting();

}

}

sortAll();

buildLookupIndex();

synchronized (MtpDeviceIndex.this) {

if (mDevice != getDevice()) throw new IndexingException();

copyResults();

/*

* In order for getBuckets to operate in constant time for descending

* order, we must precompute a reversed array of the buckets, mainly

* because the android.widget.SectionIndexer interface which adapters

* that call getBuckets implement depends on section numbers to be

* ascending relative to the scroll position, so we must have this for

* descending order or the scrollbar goes crazy.

*/

computeReversedBuckets();

mProgress = Progress.Finished;

if (mProgressListener != null) {

mProgressListener.onIndexFinish();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值