Frage

I am trying to find out the size of each file in my Box drive to display it in my list adapter much like the way it is shown in the official Box Android app.

Here is my code segment:

    BoxTypedObject item = getItem(position);
    if (item instanceof BoxAndroidFile) {
        BoxAndroidFile file = (BoxAndroidFile) item;
        Log.d(TAG, "file.getsize=" + file.getSize());
     }

The file is valid, and file.getName() works just fine. However, file.getSize() is always returning null.

Am I using the correct API or using it the right way?

War es hilfreich?

Lösung

Because you did not specify the size field when you did getFolderItems() call to get folder information.

You can try below code segment.

        final ArrayList<String> itemFields = new ArrayList<String>();
        itemFields.add(BoxAndroidFile.FIELD_NAME);
        itemFields.add(BoxAndroidFile.FIELD_SIZE);
        itemFields.add(BoxAndroidFile.FIELD_EXTENSION);
        itemFields.add(BoxAndroidFile.FIELD_PARENT);

        final BoxPagingRequestObject obj = BoxPagingRequestObject
                .pagingRequestObject(limit, offset);
        obj.getRequestExtras().addFields(itemFields);

        final BoxAndroidCollection bc = (BoxAndroidCollection) boxClient
                .getFoldersManager().getFolderItems(mTargetFolderId, obj);

Andere Tipps

To control population of fields you have to use requestObject parameter. Look at https://stackoverflow.com/a/17352838/3083204

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top