有没有办法在Android设备上循环默认图库? 在我的应用程序中,我设法通过以下代码将选定的图片从默认图库传递到imageView:
public void onImageGalleryClicked(View v){
//Invoke image gallery using implicit intent
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
//Where is the image gallery stored
File pictureDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
//Get path of the image gallery as string
CurrentPicturePath = pictureDirectory.getPath();
//Get the URI-representation of the image directory path
Uri data = Uri.parse(CurrentPicturePath);
//Set the data and type to get all the images
photoPickerIntent.setDataAndType(data, "image/*");
//Invoke activity and wait for result
startActivityForResult(photoPickerIntent, IMAGE_GALLERY_REQUEST);
}
通过以下方式在viewcontroller中显示图片:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK){
if(requestCode == IMAGE_GALLERY_REQUEST){
//Address of the image on SD-card
Uri imageUri = data.getData();
//Declare a stream to read the image from SD-card
InputStream inputStream;
try {
inputStream = getContentResolver().openInputStream(imageUri);
//Get a bitmap
Bitmap image = BitmapFactory.decodeStream(inputStream);
imgPicture.setImageBitmap(image);
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, "Unable to open image!", Toast.LENGTH_LONG).show();
}
}
}
}
现在我想在我的应用中找到一个按钮,找到默认图库中的下一张图片。 我喜欢在图库中循环查找当前图片(通过路径/名称!?)以便能够选择下一个(或之前的)
的方法答案 0 :(得分:0)
数十亿台Android设备分布在数千种设备型号中。这些将有数百个不同的"默认图像库"应用程序,因为它们通常由设备制造商编写。用户无需使用任何这些应用来满足您的ACTION_PICK
请求。
ACTION_PICK
实施不需要为您提供" next"或"转发"信息。