Android获取非本地照片中的属性
时间: 2024-02-25 22:52:56 浏览: 21
要获取非本地照片中的属性,您需要使用Android中的ContentProvider来查询照片的属性。ContentProvider可以提供数据,包括媒体数据,例如照片、音频和视频数据。以下是一个获取非本地照片属性的示例代码:
```java
String[] projection = {MediaStore.Images.Media.DATA, MediaStore.Images.Media.SIZE};
String selection = MediaStore.Images.Media._ID + "=?";
String[] selectionArgs = {String.valueOf(imageId)};
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null);
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.SIZE);
long fileSize = cursor.getLong(columnIndex);
columnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
String imagePath = cursor.getString(columnIndex);
//在这里使用获取到的属性值
}
cursor.close();
```
此代码使用MediaStore.Images.Media.EXTERNAL_CONTENT_URI查询非本地照片的属性。它使用照片的ID来选择特定的照片,并从查询结果中获取SIZE和DATA属性值。您可以根据需要更改投影和选择参数以获取其他属性值。