考虑如下图所示的场景:
三张照片,其中一张是大型GIF文件(3MP).
我正在查询MediaStore以检索相应的缩略图.如果我使用此sortOrder通过CursorLoader初始化Cursor:
MediaStore.Images.Media.DATE_ADDED + " DESC""
Run Code Online (Sandbox Code Playgroud)
会发生什么: MediaStore返回先前成功检索的缩略图:
预期的行为:当MediaStore由于某种原因无法检索给定图像的缩略图时,它必须返回NULL,根据其Javadoc:"...返回一个Bitmap实例.如果与origId关联的原始图像不是,则它可以为null存在或记忆不够."
如果我用这个sortOrder初始化Cursor:
MediaStore.Images.Media.DATE_ADDED + " ASC""
Run Code Online (Sandbox Code Playgroud)
它运行得很好:
但是我不能简单地改变sortOrder,因为要求是先显示最新的图片.
下面是我的示例代码,这里是完整的示例项目以及用于重现的三个图像.
package com.example.getimagefrommediastore;
import android.app.Activity;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.content.CursorLoader;
import android.widget.ImageView;
import android.widget.TextView;
public class GetThumbnailsFromMediaStoreSampleActivity extends Activity {
TextView mThumb_id_01;
TextView mThumb_id_02;
TextView mThumb_id_03;
ImageView mImg_01;
ImageView mImg_02;
ImageView mImg_03;
boolean isThumb01 = true; // Simple flag to control this example
boolean isThumb02 = true;
Cursor mCursorLoader;
int mColumnIndex;
long …Run Code Online (Sandbox Code Playgroud) 我正在对Android的MediaStore文件数据库查询- - MediaStore.Files.getContentUri("external"),对于某些特定的文件夹,无论是MediaStore.MediaColumns.TITLE和MediaStore.MediaColumns.DISPLAY_NAME是零,而其他文件夹,这个值存在.我找不到任何关于MediaStore.MediaColumns.TITLE可能为null的文档.
对于一些内部Android目录会发生这种情况,例如:
_data: /storage/emulated/0/Music, title: null, _display_name: null
_data: /storage/emulated/0/Notifications, title: null, _display_name: null
_data: /storage/emulated/0/Pictures, title: null, _display_name: null
Run Code Online (Sandbox Code Playgroud)
但是,对于其他一些文件夹,标题是:
_data: /storage/emulated/0/Android, title: Android, _display_name: null
_data: /storage/emulated/0/DCIM, title: DCIM, _display_name: null
_data: /storage/emulated/0/Download, title: Download, _display_name: null
Run Code Online (Sandbox Code Playgroud)
所有数据都直接来自MediaStore查询.
我知道我可以直接使用数据但我正在尝试根据TITLE对查询进行排序,这会导致错误的结果,因为有些是null.
这是预期的行为吗?如何处理它并检索按标题正确排序的所有文件?
我在 Play 商店中有一个应用程序,该应用程序targetSdkVersion已更新为30from 29,更新后该应用程序一次又一次被 Google Play 拒绝。
MANAGE_EXTERNAL_STORAGE此前, SDK Manifest 中有一项权限。
从我的应用程序中完全删除MANAGE_EXTERNAL_STORAGE 权限和存储权限 (WRITE_EXTERNAL_STORAGE ) 后,将应用程序上传到商店,应用程序更新再次被拒绝。
这是从 Google Play 收到的拒绝原因电子邮件。
注意:我将所有媒体文件保存在应用程序特定的内部存储中。
另外,我在我的 SDK 中获得了许可READ_EXTERNAL_STORAGE,因为我们的应用程序中有聊天功能,可以获取设备的图像和视频来发送。
根据许可没有影响。Use of All files access (MANAGE_EXTERNAL_STORAGE) permission READ_EXTERNAL_STORAGE
更新
我也删除了READ_EXTERNAL_STORAGE该应用程序的权限,但仍然遭到 Google Play 出于相同原因的拒绝。
是存储策略的问题还是其他问题?
mediastore google-play google-play-console scoped-storage android-11
我有一个活动,其中一个viewflipper显示一个包含来自mediastore的艺术家的列表,onitem点击显示所选艺术家的专辑列表,然后显示该专辑中的歌曲.单击一首歌后,它应该使用字符串'title'填充textview.
在此之前,所有游标都工作正常,但最后一个游标似乎以某种方式失去了位置.谁能告诉我为什么logcat告诉我:
05-07 23:58:54.195: E/AndroidRuntime(1961): java.lang.IllegalStateException: Couldn't read row 3, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
Run Code Online (Sandbox Code Playgroud)
无法读取的特定行因所选择的艺术家/专辑/歌曲而异.代码如下.非常感谢您的帮助.
package music.flipper;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.MediaStore.Audio.AlbumColumns;
import android.provider.MediaStore.Audio.ArtistColumns;
import android.provider.MediaStore.Audio.AudioColumns;
import android.provider.MediaStore.MediaColumns;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class MusicFlipper extends Activity implements OnItemClickListener {
/** Called when the activity is first created. */
ViewFlipper viewflipper; …Run Code Online (Sandbox Code Playgroud) 在我的android文档中,我没有micro_kind和mini_kind的含义,这两者有什么区别?
说到图像显示两者有什么区别?
关注问题: MediaStore.Images和MediaStore.Video有什么不同,仍然给出图像的输出,路径包含视频路径,为什么我甚至使用mediastore.images.thumbnail.mini_kind它仍然显示图像呢?
Bitmap bmp = ThumbnailUtils.createVideoThumbnail(videoPath,
MediaStore.Images.Thumbnails.MINI_KIND);
Bitmap bmp = ThumbnailUtils.createVideoThumbnail(videoPath,
MediaStore.Video.Thumbnails.MINI_KIND);
Run Code Online (Sandbox Code Playgroud) 我打算查询 MediaStore.Images.Media.BUCKET_DISPLAY_NAME 字段,但 Android Studio 表示它仅适用于 API 29+。此外,Android 文档也有同样的说法。
但是,当他们使用相同的字段时,我发现了 2017 年的StackOverflow 帖子。
我在这里缺少什么?
谢谢你。
编辑:我也在 Android 9.0 模拟器上试过它,它工作得很好。
对于我的应用程序,我一直在使用我自己的Camera类来拍摄图像和我自己的数据库但很快就无法跟上变化,我决定使用Android内置的相机应用程序来完成这项工作,但是我似乎无法得到它来保存文件.我在这里错过了什么?该应用程序似乎保存文件,但它只是0字节.我查找了Camera应用程序的源代码,并在Extras中查找"输出"以保存文件.任何帮助将不胜感激.
Public class CameraTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button cameraButton = (Button) findViewById(R.id.cameraButton);
cameraButton.setOnClickListener( new OnClickListener(){
public void onClick(View v ){
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("output", uri.getPath());
startActivityForResult(intent,0);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode== 0 && …Run Code Online (Sandbox Code Playgroud) 所以我试图让用户使用我在这里描述的方法使用我的Android应用程序选择一个特定的媒体: 在我的Android应用程序中访问图片应用程序中的图片
它工作得很好,除了我可以看似只在视频或照片之间选择以向用户呈现,而不是同时.有一个很好的方法来做到这一点:
startActivityForResult(new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI),SELECT_IMAGE);
谢谢!
随着更新的Android Q的出现,许多事情发生了变化,尤其是在范围存储和file:///URI 逐渐弃用的情况下。问题是缺少有关如何在Android Q设备上正确处理媒体文件的文档。
我有一个媒体文件(音频)管理应用程序,但找不到一种可靠的方法来告诉OS我对文件进行了更改,以便它可以更新其MediaStore记录。
选项1:MediaScannerService
MediaScannerConnection.scanFile(context, new String[]{ filePath }, new String[]{"audio/*"}, new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String s, Uri uri) {
}
});
Run Code Online (Sandbox Code Playgroud)
file://主存储中的URIfile://辅助存储(例如可移动存储)中的URIcontent://URI选项2:广播
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
Run Code Online (Sandbox Code Playgroud)
选项3:手动插入MediaStore
AudioFileContentValues是来自的某些列值MediaStore.Audio.AudioColumns。
基于file://URI的旧方法:
Uri uri = MediaStore.Audio.Media.getContentUriForPath(file_path);
newUri = context.getContentResolver().insert(uri, AudioFileContentValues);
Run Code Online (Sandbox Code Playgroud)
MediaStore.Audio.Media.getContentUriForPath 不推荐使用基于我可以从文档中得出的新方法:
Uri collection = MediaStore.Audio.Media.getContentUri(correctVolume);
newUri = context.getContentResolver().insert(collection, AudioFileContentValues);
Run Code Online (Sandbox Code Playgroud)
哪里correctVolume会external从主存储,同时它会是这样的0000-0000二级存储,根据该文件的位置。 …
android mediastore android-contentresolver android-external-storage android-10.0
我在片段中有一个回收者视图,基本上我试图在回收者视图中加载歌曲列表.每行回收者视图包含一个imageview(用于专辑封面)和textview(用于歌曲名称).我遇到麻烦,当数据集的大小很大时,即当歌曲太多时,回收者视图滞后,应用程序最终给出ANR.我正在使用Glide在每行的imageview中加载专辑艺术.谷歌音乐播放器如何能够显示如此大量的歌曲而没有任何延迟?
编辑: 这是我的SongsFragment
public class SongsFragment extends Fragment {
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
ProgressBar progressBar; // progress bar to show after every 30 items
NestedScrollView nestedScrollView; //for smooth scrolling of recyclerview as well as to detect the end of recyclerview
RecyclerView recyclerView;
ArrayList<Song> songMainList = new ArrayList<>(); //partial list in which items are added
ArrayList<Song> songAllList = new ArrayList<>(); //Complete List of songs
SongAdapter songsAdapter;
private LinearLayoutManager layoutManager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, …Run Code Online (Sandbox Code Playgroud) android mediastore recycler-adapter android-recyclerview android-glide
mediastore ×10
android ×9
android-10.0 ×2
android-11 ×1
camera ×1
cursor ×1
google-play ×1
java ×1
listview ×1
photo ×1
sql-order-by ×1
video ×1
viewflipper ×1