gpt4 book ai didi

android - 如何打开图片/视频/音频?

转载 作者:行者123 更新时间:2023-11-30 03:01:53 32 4
gpt4 key购买 nike

在我的应用程序中有一个按钮,当按下该按钮时,应该会打开图片库、视频库或音频播放器。

请问我将如何构建执行该操作的 Intent ?

最佳答案

尝试使用这种方法,只需单击任何按钮即可传递文件路径,然后此方法根据该文件对任何类型的文件进行 poen

 File file = new File(filePath); 
MimeTypeMap map = MimeTypeMap.getSingleton();
String ext = MimeTypeMap.getFileExtensionFromUrl(file.getName());
String type = map.getMimeTypeFromExtension(ext);
if (type == null)
type = "*/*";

Uri uri = Uri.parse("www.google.com");
Intent type_intent = new Intent(Intent.ACTION_VIEW, uri);
Uri data = Uri.fromFile(file);
type_intent.setDataAndType(data, type);
startActivity(type_intent);

图片

private void getallimages(File dir)
{

String[] STAR = { "*" };
controller.images.clear();

final String orderBy = MediaStore.Images.Media.DEFAULT_SORT_ORDER;
Cursor imagecursor = cntx.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, STAR, null, null, orderBy);
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
int count = imagecursor.getCount();
for (int i = 0; i < count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
ImageItem imageItem = new ImageItem();//this is my wrapper class
if(new File(imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA))).length()<=10485760)
{
imageItem.filePath = imagecursor.getString(imagecursor.getColumnIndex(MediaStore.Images.Media.DATA));

imageItem.id = id;
imageItem.selection = false; //newly added item will be selected by default this it do for check box unselect u dont need to fill this
controller.images.add(imageItem);//this i just add all info in wrapper class

}

}

音频

private void getallaudio()
{
String[] STAR = { "*" };
controller.audioWrapper.clear();
Cursor audioCursor = cntx.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null);
if (audioCursor != null)
{
if (audioCursor.moveToFirst())
{
do
{

String path = audioCursor.getString(audioCursor.getColumnIndex(MediaStore.Audio.Media.DATA));


controller.audioWrapper.add(new MediaWrapper(new File(path).getName(), path, "Audio",false));



}while (audioCursor.moveToNext());

}
}


}

和视频

private void getallvideo()
{
String[] STAR = { "*" };

controller.videoWrapper.clear();
Cursor videoCursor = cntx.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, STAR, null, null, null);

if (videoCursor != null)
{
if (videoCursor.moveToFirst())
{
do
{


String path = videoCursor.getString(videoCursor.getColumnIndex(MediaStore.Images.Media.DATA));

controller.videoWrapper.add(new MediaWrapper(new File(path).getName(), path, "Video",false,color_string));




}while (videoCursor.moveToNext());

}
}
}

关于android - 如何打开图片/视频/音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22401363/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com