我想在listview中显示带有专辑名称的专辑封面.但我没有得到显示专辑封面的方式.我试过从android上的封面艺术.
这是我的代码:
Cursor cursor = managedQuery(MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, null, null, null, null);
if (cursor == null)
{
//Query Failed , Handle error.
}
else if (!cursor.moveToFirst())
{
//No media on the device.
}
else
{
int titleColumn = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ART);
int id = cursor.getColumnIndex(android.provider.MediaStore.Audio.Albums.ALBUM_ID); //here value i m getting -1 .
for(int i=0;i<cursor.getCount();i++)
{
if(id<0)
{
Long album =Long.parseLong(cursor.getString(id));
String coverPath = cursor.getString(titleColumn);
Context context = null;
ContentResolver res = context.getContentResolver();
Uri uri = ContentUris.withAppendedId(sArtworkUri, album);
if (uri != null)
{ …Run Code Online (Sandbox Code Playgroud) android albumart mediastore android-contentresolver android-mediaplayer
我注意到MediaStore.Images.ImageColumns的一个奇怪的列叫做" MINI_THUMB_MAGIC ".
文档说的只是:
迷你拇指id.
类型:INTEGER
常数值:"mini_thumb_magic"
我的猜测是这个字段与MediaStore.Images.Thumbnails有关.
这是对的吗 ?如果没有,这是什么以及如何使用它?
如果它是正确的,我还有其他相关的问题:
它是原始图像的迷你尺寸图像吗?它使用相同的宽高比还是对它进行中心裁剪?
为什么"MICRO"的大小是方形(96 x 96),"MINI"的大小是非方形矩形(512 x 384)?
你如何使用它?我的猜测是,它是通过使用"做THUMB_DATA ",这是一个blob,所以你使用它像这样,但是那又有什么用"的宗旨getThumbnail "如果你已经有了这个领域?
如果方向值不为0,它会获得旋转的缩略图吗?意思是如果我想展示它,我不需要旋转图像?
是否可以与缩略图一起查询图像?也许使用内连接?
它适用于所有Android设备和版本吗?
为什么它甚至被称为"魔术"?是因为它也适用于视频(由于某种原因,音乐不存在,例如,它可能是专辑的封面照片)?
sql android mediastore android-contentresolver android-gallery
我试图让所有文件名都包含音频文件我已经使用Mediastore来获取媒体商店音频,专辑,播放列表和音频数据,但我如何获得包含音频文件的文件或文件夹标题.这是我尝试过的代码,但它不正确,因为我无法设置External_Content_uri.这是我试过的代码.
private void External() {
try {
String[] proj = {MediaStore.Files.FileColumns.TITLE,
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.PARENT,
MediaStore.Files.FileColumns.DATA
};// Can include more data for more details and check it.
String selection =MediaStore.Files.FileColumns.MEDIA_TYPE+"=?";
String[] selectionArgs = {"MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO"};
String sortOrder = MediaStore.Audio.Media.TITLE + " ASC";
Cursor audioCursor = getContentResolver().query(MediaStore.Files.getContentUri("\"external\""), proj, selection, selectionArgs, sortOrder);
if (audioCursor != null) {
if (audioCursor.moveToFirst()) {
do {
int filetitle = audioCursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE);
int file_id = audioCursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID);
int fileparent = audioCursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.PARENT);
int filedata = audioCursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA);
Mediafileinfo info = new Mediafileinfo(); …Run Code Online (Sandbox Code Playgroud) 我正在尝试更新音频文件的流派标签。
码
final Uri genreUri = MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI;
String currentGenreName = MediaStore.Audio.Genres.NAME;
ContentValues values2 = new ContentValues();
values2.put(currentGenreName, genre);
String whereGenre = MediaStore.Audio.Genres._ID + "=?";
String[] whereVal2 = {Long.toString(genreID)};
resolver.update(genreUri, values2, whereGenre, whereVal2);
Run Code Online (Sandbox Code Playgroud)
我没有收到任何错误,但是MediaStore流派表中的流派没有更新。
其他标签(如标题,艺术家,专辑和艺术品)已更新,仅流派无效。
我也找不到有关更新音频文件中流派名称的任何信息,我只能通过上面的标签来做到这一点。
编辑
我用于编辑标题,艺术家,专辑名称和年份标签的代码,效果很好,所以我认为我必须对类型名称进行相同的操作,因为我具有类型ID。
final Uri musicUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
ContentResolver resolver = c.getContentResolver();
String currentTitle = MediaStore.Audio.Media.TITLE;
String currentArtist = MediaStore.Audio.Media.ARTIST;
String currentAlbumID = MediaStore.Audio.Media.ALBUM_ID;
String currentAlbum = MediaStore.Audio.Media.ALBUM;
String currentGenreID = MediaStore.Audio.Genres._ID;
String currentGenreName = MediaStore.Audio.Genres.NAME;
String currentAlbumData = MediaStore.Audio.Media.DATA;
String currentYear …Run Code Online (Sandbox Code Playgroud) 更新媒体商店中音频文件的元数据不适用于 Android Q 操作系统,它适用于所有其他操作系统。
我正在使用 uri 指定为 MediaStore.Audio.Media.EXTERNAL_CONTENT_URI 的内容提供程序。它在所有低于 Android Q 的设备上运行良好。下面是我用来更新轨道元数据的代码。
ContentValues cv = new ContentValues();
ContentResolver resolver = getContentResolver();
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
cv.put(MediaStore.Audio.Media.TITLE, newTitle);
cv.put(MediaStore.Audio.Media.ALBUM, newAlbumName);
cv.put(MediaStore.Audio.Media.ARTIST, newArtistName);
int rowsUpdated = resolver.update(uri, cv,
MediaStore.Audio.Media._ID + " = ? ", new String[]{audioId});
Run Code Online (Sandbox Code Playgroud)
对于 Android Q 设备,rowsUpdated 始终为 0,无一例外。其他音乐播放器如何更新 Android Q 中的曲目元数据?
android mediastore android-music-player android-contentprovider android-10.0
Android 问:我需要从我保存图像的特定目录中获取图像列表,并将这些图像显示在我的应用程序上。
保存图片代码:
final String relativeLocation = Environment.DIRECTORY_PICTURES + File.separator + "MyMedia" + File.separator + "Photo";
ContentResolver resolver = context.getContentResolver();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, name);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, relativeLocation);
Uri imageUri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues);
fos = resolver.openOutputStream(Objects.requireNonNull(imageUri));
bmp.compress(Bitmap.CompressFormat.JPEG,100, fos);
Objects.requireNonNull(fos).close();
Objects.requireNonNull(fos).flush();
Run Code Online (Sandbox Code Playgroud)
获取图片代码:
Uri externalUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {
MediaStore.Files.FileColumns._ID,
MediaStore.Images.Media.DATE_TAKEN,
MediaStore.MediaColumns.TITLE,
MediaStore.Images.Media.MIME_TYPE,
MediaStore.MediaColumns.RELATIVE_PATH
};
Cursor cursor = context.getContentResolver().query(externalUri, projection, null, null, MediaStore.Images.Media.DATE_TAKEN +" DESC");
int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
int titleColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.TITLE);
int relativePathColumn = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.RELATIVE_PATH); …Run Code Online (Sandbox Code Playgroud) 我正在通过查询 MediaStore 从设备读取缩略图,使用MediaStore.Images.Thumbnails.getThumbnail(). 但是,这在 Android 10 (API 29) 中已被弃用,并指向ContentResolver#loadThumbnail:https : //developer.android.com/reference/android/provider/MediaStore.Images.Thumbnails
但是,我无法让它工作(在运行 API 29 的模拟设备中)。我已将一些 JPEG 复制到模拟设备上,最终位于下载文件夹中。它们在照片应用程序中显示良好。下面的代码给了我一个 FileNotFoundException。“无内容提供者”实际上告诉我什么?
try {
Size thumbSize = new Size(100, 100);
Uri thumbUri = Uri.fromFile(new File(imgPath));
// imgPath: /storage/emulated/0/Download/pexels-photo-323490.jpeg
// thumbUri: file:///storage/emulated/0/Download/pexels-photo-323490.jpeg
Bitmap thumbBitmap;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
thumbBitmap = mContext.getContentResolver().loadThumbnail(thumbUri, thumbSize, null);
} else {
thumbBitmap = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(),
imgId, MediaStore.Images.Thumbnails.MINI_KIND, null);
}
iconView.setImageBitmap(thumbBitmap);
} catch (Exception e) {
Log.e("err", e.toString());
}
Run Code Online (Sandbox Code Playgroud)
例外:
java.io.FileNotFoundException: No content provider: file:///storage/emulated/0/Download/pexels-photo-323490.jpeg
Run Code Online (Sandbox Code Playgroud) 到目前为止,我检查文件是否存在,如果不存在,则将其保存到 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) 中的设备,但 Android 10 不支持它。
所以我尝试使用 mediastore API 来保存图像。
READ_STORAGE_PERMISSION -> 不允许
首先,我使用以下代码查询 contentresolver 以检查文件是否存在:
Uri collection = null;
collection = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
String[] PROJECTION = new String[]{MediaStore.Images.Media.DISPLAY_NAME,
MediaStore.MediaColumns.RELATIVE_PATH};
String QUERY = MediaStore.Files.FileColumns.RELATIVE_PATH + " like ? and " +
MediaStore.Files.FileColumns.DISPLAY_NAME + " like ?";
ContentResolver mContentResolver = this.getContentResolver();
Cursor cursor = mContentResolver.query(collection, PROJECTION, QUERY , new String[]{"%" + dirName + "%", "%" + fname + "%"}, null);
if (cursor != null) {
Log.d("upisdk", "cursor != null");
if (cursor.getCount() > …Run Code Online (Sandbox Code Playgroud) 我正在使用媒体商店在回收站视图中列出 pdf。它在android 10 之前都可以正常工作,也可以在 android 11 中运行,但只能在 android 10 中运行。
我也在requestLegacyExternalStorage=true清单中设置了。
在build.gradle
compileSdkVersion 29
buildToolsVersion "30.0.2"
minSdkVersion 21
targetSdkVersion 29
Run Code Online (Sandbox Code Playgroud)
获取PDF.kt
class FetchPdf(private val applicationContext: Context) {
private val arrayList = ArrayList<Pdf>()
fun getPdf(): ArrayList<Pdf> {
val collection = MediaStore.Files.getContentUri("external")
val projection = arrayOf(
MediaStore.Files.FileColumns._ID,
MediaStore.Files.FileColumns.DATE_MODIFIED,
MediaStore.Files.FileColumns.DISPLAY_NAME,
MediaStore.Files.FileColumns.SIZE,
MediaStore.Files.FileColumns.DATA
)
val mimeType = "application/pdf"
val whereClause = MediaStore.Files.FileColumns.MIME_TYPE + " IN ('" + mimeType + "')"
val orderBy = MediaStore.Files.FileColumns.DATE_MODIFIED + " DESC"
val cursor: …Run Code Online (Sandbox Code Playgroud) 我的应用程序将 .jpg 文件移动到其他文件夹,并在我已 sendBroadcast ACTION_MEDIA_MOUNTED 的图库中查看
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
Environment.getExternalStorageDirectory() )));
Run Code Online (Sandbox Code Playgroud)
但这需要很多时间..我明白(也许)我必须直接使用 mediaStore 中的光标/contentResolver 手动更新才能更快。谁可以帮我这个事?谢谢..我的代码实际上是:
Uri uri = (Uri) list.get(cont);
Cursor cursor = managedQuery(uri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String app = cursor.getString(column_index);
File orig = new File( app.toString());
File dest = new File( destination_path +"/"+ orig.getName().toString());
orig.renameTo(dest);
Run Code Online (Sandbox Code Playgroud)
这样我将一个文件从一个路径移动到另一个路径。
之后,要在图库中获取图像,我必须发送Broadcast ACTION_MEDIA_MOUNTED
android ×10
mediastore ×10
albumart ×1
android-10.0 ×1
android-11 ×1
android-file ×1
image ×1
java ×1
move ×1
sql ×1
uri ×1