當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。