当前位置: 首页>>代码示例>>Java>>正文


Java OpenableColumns.SIZE属性代码示例

本文整理汇总了Java中android.provider.OpenableColumns.SIZE属性的典型用法代码示例。如果您正苦于以下问题:Java OpenableColumns.SIZE属性的具体用法?Java OpenableColumns.SIZE怎么用?Java OpenableColumns.SIZE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.provider.OpenableColumns的用法示例。


在下文中一共展示了OpenableColumns.SIZE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: query

@Override
public Cursor query(Uri uri, String[] projection, String selection,
					String[] selectionArgs, String sortOrder) {
	if (1 == uriMatcher.match(uri)) {
		MatrixCursor cursor = null;
		File file = new File(getContext().getCacheDir() + File.separator
				+ DSCApplication.LOGS_FOLDER_NAME + File.separator
				+ uri.getLastPathSegment());
		if (file.exists()) {
			cursor = new MatrixCursor(new String[]{
					OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE});
			cursor.addRow(new Object[]{uri.getLastPathSegment(),
					file.length()});
		}
		return cursor;
	}
	return null;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:18,代码来源:CachedFileProvider.java

示例2: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri           A content URI returned by {@link #getUriForFile}.
 * @param projection    The list of columns to put into the {@link Cursor}. If null all columns are
 *                      included.
 * @param selection     Selection criteria to apply. If null then all data that matches the content
 *                      URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 *                      the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 *                      right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 *                      <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 *                      values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder     A {@link java.lang.String} containing the column name(s) on which to sort
 *                      the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:57,代码来源:FileProvider.java

示例3: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri A content URI returned by {@link #getUriForFile}.
 * @param projection The list of columns to put into the {@link Cursor}. If null all columns are
 * included.
 * @param selection Selection criteria to apply. If null then all data that matches the content
 * URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 * values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort
 * the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 *
 */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:GigigoGreenLabs,项目名称:permissionsModule,代码行数:58,代码来源:FileProvider.java

示例4: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the PublicFileProvider.
 * PublicFileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri A content URI returned by {@link #getUriForFile}.
 * @param projection The list of columns to put into the {@link Cursor}. If null all columns are
 * included.
 * @param selection Selection criteria to apply. If null then all data that matches the content
 * URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 * values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort
 * the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 *
 */
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    File file = strategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] columns = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String column : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(column)) {
            columns[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(column)) {
            columns[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    columns = copyOf(columns, i);
    values = copyOf(values, i);

    MatrixCursor cursor = new MatrixCursor(columns, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:cketti,项目名称:PublicFileProvider,代码行数:56,代码来源:PublicFileProvider.java

示例5: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link OpenableColumns}:
 * <ul>
 * <li>{@link OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri           A content URI returned by {@link #getUriForFile}.
 * @param projection    The list of columns to put into the {@link Cursor}. If null all columns are
 *                      included.
 * @param selection     Selection criteria to apply. If null then all data that matches the content
 *                      URI is returned.
 * @param selectionArgs An array of {@link String}, containing arguments to bind to
 *                      the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 *                      right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 *                      <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 *                      values are bound to <i>selection</i> as {@link String} values.
 * @param sortOrder     A {@link String} containing the column name(s) on which to sort
 *                      the resulting {@link Cursor}.
 *
 * @return A {@link Cursor} containing the results of the query.
 */
@Override
public Cursor query(@NotNull Uri uri, @Nullable String[] projection, @Nullable String selection,
                    @Nullable String[] selectionArgs,
                    @Nullable String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:StepicOrg,项目名称:stepik-android,代码行数:59,代码来源:GenericFileProvider.java

示例6: query

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    String uriPath = uri.getLastPathSegment();
    if (uriPath == null) {
        return null;
    }
    if (projection == null) {
        projection = new String[] {
                BaseColumns._ID,
                MediaStore.MediaColumns.DATA,
                OpenableColumns.DISPLAY_NAME,
                OpenableColumns.SIZE
        };
    }
    // If we receive a query on display name or size,
    // we should block until the image is ready
    mImageReadyCond.block();

    File path = new File(uriPath);

    MatrixCursor cursor = new MatrixCursor(projection);
    Object[] columns = new Object[projection.length];
    for (int i = 0; i < projection.length; i++) {
        if (projection[i].equalsIgnoreCase(BaseColumns._ID)) {
            columns[i] = 0;
        } else if (projection[i].equalsIgnoreCase(MediaStore.MediaColumns.DATA)) {
            columns[i] = uri;
        } else if (projection[i].equalsIgnoreCase(OpenableColumns.DISPLAY_NAME)) {
            columns[i] = path.getName();
        } else if (projection[i].equalsIgnoreCase(OpenableColumns.SIZE)) {
            columns[i] = path.length();
        }
    }
    cursor.addRow(columns);

    return cursor;
}
 
开发者ID:asm-products,项目名称:nexus-gallery,代码行数:37,代码来源:SharedImageProvider.java

示例7: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri           A content URI returned by {@link #getUriForFile}.
 * @param projection    The list of columns to put into the {@link Cursor}. If null all columns are
 *                      included.
 * @param selection     Selection criteria to apply. If null then all data that matches the content
 *                      URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 *                      the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 *                      right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 *                      <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 *                      values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder     A {@link java.lang.String} containing the column name(s) on which to sort
 *                      the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 */
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        } else if (COLUMN_LAST_MODIFIED.equals(col)) {
            cols[i] = COLUMN_LAST_MODIFIED;
            values[i++] = file.lastModified();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:andreynovikov,项目名称:trekarta,代码行数:59,代码来源:ExportProvider.java

示例8: query

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
        String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:30,代码来源:FileProvider.java

示例9: query

@Nullable
@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
	if (projection == null) {
		projection = COLUMNS;
	}
	String[] cols = new String[projection.length];
	Object[] values = new Object[projection.length];
	int i = 0;
	for (String col : projection) {
		if (OpenableColumns.DISPLAY_NAME.equals(col)) {
			cols[i] = OpenableColumns.DISPLAY_NAME;
			values[i++] = getContext().getString(R.string.export_bookmarks_file_name, DatabaseManager.getInstance().getYear());
		} else if (OpenableColumns.SIZE.equals(col)) {
			cols[i] = OpenableColumns.SIZE;
			// Unknown size, content will be generated on-the-fly
			values[i++] = 1024L;
		}
	}

	cols = copyOf(cols, i);
	values = copyOf(values, i);

	final MatrixCursor cursor = new MatrixCursor(cols, 1);
	cursor.addRow(values);
	return cursor;
}
 
开发者ID:cbeyls,项目名称:fosdem-companion-android,代码行数:27,代码来源:BookmarksExportProvider.java

示例10: query

@Nullable
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Code from FileProvider
    File file = new File(uri.getPath());
    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];

    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:infinum,项目名称:android_dbinspector,代码行数:30,代码来源:DatabaseProvider.java

示例11: query

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    // Security
    verifyCaller();

    // content providers that support open and openAssetFile should support queries for all
    // android.provider.OpenableColumns.
    int displayNameIndex = -1;
    int sizeIndex = -1;
    // If projection is null, return all columns.
    if (projection == null) {
        projection = new String[]{OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE};
    }
    for (int i = 0; i < projection.length; i++) {
        if (OpenableColumns.DISPLAY_NAME.equals(projection[i])) {
            displayNameIndex = i;
        }
        if (OpenableColumns.SIZE.equals(projection[i])) {
            sizeIndex = i;
        }
    }
    MatrixCursor cursor = new MatrixCursor(projection);
    Object[] result = new Object[projection.length];
    for (int i = 0; i < result.length; i++) {
        if (i == displayNameIndex) {
            result[i] = uri.getPath();
        }
        if (i == sizeIndex) {
            result[i] = null; // Size is unknown, so null, if it was known, it would go here.
        }
    }
    cursor.addRow(result);
    return cursor;
}
 
开发者ID:Xlythe,项目名称:ThemeEngine,代码行数:34,代码来源:FileProvider.java

示例12: query

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    // ContentProvider has already checked granted permissions
    final File file = mStrategy.getFileForUri(uri);

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:SecrecySupportTeam,项目名称:Secrecy_fDroid_DEPRECIATED,代码行数:30,代码来源:OurFileProvider.java

示例13: query

/**
 * Use a content URI returned by
 * {@link #getUriForFile(Context, String, File) getUriForFile()} to get information about a file
 * managed by the FileProvider.
 * FileProvider reports the column names defined in {@link android.provider.OpenableColumns}:
 * <ul>
 * <li>{@link android.provider.OpenableColumns#DISPLAY_NAME}</li>
 * <li>{@link android.provider.OpenableColumns#SIZE}</li>
 * </ul>
 * For more information, see
 * {@link ContentProvider#query(Uri, String[], String, String[], String)
 * ContentProvider.query()}.
 *
 * @param uri A content URI returned by {@link #getUriForFile}.
 * @param projection The list of columns to put into the {@link Cursor}. If null all columns are
 * included.
 * @param selection Selection criteria to apply. If null then all data that matches the content
 * URI is returned.
 * @param selectionArgs An array of {@link java.lang.String}, containing arguments to bind to
 * the <i>selection</i> parameter. The <i>query</i> method scans <i>selection</i> from left to
 * right and iterates through <i>selectionArgs</i>, replacing the current "?" character in
 * <i>selection</i> with the value at the current position in <i>selectionArgs</i>. The
 * values are bound to <i>selection</i> as {@link java.lang.String} values.
 * @param sortOrder A {@link java.lang.String} containing the column name(s) on which to sort
 * the resulting {@link Cursor}.
 * @return A {@link Cursor} containing the results of the query.
 */
@Override public Cursor query(Uri uri, String[] projection, String selection,
    String[] selectionArgs, String sortOrder) {
  // ContentProvider has already checked granted permissions
  final File file = mStrategy.getFileForUri(uri);

  if (projection == null) {
    projection = COLUMNS;
  }

  String[] cols = new String[projection.length];
  Object[] values = new Object[projection.length];
  int i = 0;
  for (String col : projection) {
    if (OpenableColumns.DISPLAY_NAME.equals(col)) {
      cols[i] = OpenableColumns.DISPLAY_NAME;
      values[i++] = file.getName();
    } else if (OpenableColumns.SIZE.equals(col)) {
      cols[i] = OpenableColumns.SIZE;
      values[i++] = file.length();
    }
  }

  cols = copyOf(cols, i);
  values = copyOf(values, i);

  final MatrixCursor cursor = new MatrixCursor(cols, 1);
  cursor.addRow(values);
  return cursor;
}
 
开发者ID:mattprecious,项目名称:telescope,代码行数:56,代码来源:FileProvider.java

示例14: query

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
                    String sortOrder) {
    java.io.File f = new java.io.File(Global.INSTANCE.getCacheDir(), SHARE_FILE);
    if (!f.exists()) {
        throw new RuntimeException("Operation not supported");
    }
    String path = f.getPath();

    VirtualFileSystem vfs = VirtualFileSystem.get();
    vfs.setContainerPath(path);
    if (!vfs.isMounted()) vfs.mount(path, Global.INSTANCE.getOrmHelper().getPassword());

    File file = new File("/", uri.getPath().replace(FILES_URI.getPath(),""));

    if (projection == null) {
        projection = COLUMNS;
    }

    String[] cols = new String[projection.length];
    Object[] values = new Object[projection.length];
    int i = 0;
    for (String col : projection) {
        if (OpenableColumns.DISPLAY_NAME.equals(col)) {
            cols[i] = OpenableColumns.DISPLAY_NAME;
            values[i++] = file.getName();
        } else if (OpenableColumns.SIZE.equals(col)) {
            cols[i] = OpenableColumns.SIZE;
            values[i++] = file.length();
        }
    }

    cols = copyOf(cols, i);
    values = copyOf(values, i);

    final MatrixCursor cursor = new MatrixCursor(cols, 1);
    cursor.addRow(values);
    return cursor;
}
 
开发者ID:securityfirst,项目名称:Umbrella_android,代码行数:39,代码来源:IOCipherContentProvider.java

示例15: handleFileChosen

public void handleFileChosen(Uri file_uri) {
    Activity activity = getActivity();

    String filename = "no_filename";
    long size = 0;

    if (file_uri.getScheme().compareTo("content") == 0) {
        ContentResolver cr = activity.getContentResolver();

        String[] projection = {MediaStore.MediaColumns.DISPLAY_NAME};
        Cursor metaCursor = cr.query(file_uri, projection, null, null, null);
        if (metaCursor != null) {
            try {
                if (metaCursor.moveToFirst()) {
                    filename = metaCursor.getString(0);
                }
            } finally {
                metaCursor.close();
            }
        }

        projection = new String[]{OpenableColumns.SIZE};
        metaCursor = cr.query(file_uri, projection, null, null, null);
        if (metaCursor != null) {
            try {
                if (metaCursor.moveToFirst()) {
                    size = metaCursor.getLong(0);
                }
            } finally {
                metaCursor.close();
            }
        }

        if (size <= 0) {
            Cursor cursor = cr.query(file_uri, null, null, null, null);
            if (cursor != null) {
                try {
                    if (cursor.moveToFirst()) {
                        int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
                        Uri filePathUri = Uri.parse(cursor.getString(column_index));
                        filename = filePathUri.getLastPathSegment();
                        size = new File(file_uri.getPath()).length();
                        cursor.close();
                    }
                } finally {
                    cursor.close();
                }
            }
        }
    } else if (file_uri.getScheme().compareTo("file") == 0) {
        filename = file_uri.getLastPathSegment();
        size = new File(file_uri.getPath()).length();
    } else {
        filename += "_" + file_uri.getLastPathSegment();
        size = new File(file_uri.getPath()).length();
    }

    if (filename.contains(":")) filename = filename.replace(":", ".");
    if (!filename.contains(".")) filename += ".bin";
    edit_filename.setText(filename);

    if (size > 0) {
        try {
            InputStream is = activity.getContentResolver().openInputStream(file_uri);
            input = file_uri;
            filesize = size;
            Toast.makeText(getActivity(),
                    getString(R.string.file_chosen, edit_filename.getText()), Toast.LENGTH_SHORT).show();
            if (is != null) is.close();
        } catch (Exception e) {
            Toast.makeText(getActivity(), getString(R.string.error_formatted,
                    e.toString()), Toast.LENGTH_SHORT).show();
        }
    }
}
 
开发者ID:vit1-irk,项目名称:idec-mobile,代码行数:75,代码来源:FileUploadFragment.java


注:本文中的android.provider.OpenableColumns.SIZE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。