有没有人碰巧知道这个教程?看起来这是一个相当普遍的兴趣,我已经看到了一些相关的东西,但最近没有特别解决它。
例如,当您单击底栏中的照片按钮时,facebook安卓应用程序就会执行此操作。
我想检索下载和图库中的所有照片,无论手机是否有SD卡。
非常感谢你!
答案 0 :(得分:1)
如果您想为用户选择显示现有照片,请执行以下操作:
private static final int _GALLERY_PHOTO_REQUEST = 2;
...
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(intent, "Choose a Photo"), _GALLERY_PHOTO_REQUEST);
然后,我这样做(一旦用户选择或取消照片选择器):
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
// I'm using an if{} block here, if you have multiple resultCodes to check, then use a switch{} block.
if (Activity.RESULT_OK == resultCode)
{
if (requestCode == _GALLERY_PHOTO_REQUEST)
{
Uri uri = data.getData();
// Do something with the chosen photo, such as my custom method to process the photo
processPhoto(uri);
}
else
{
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
else
{
String msg = String.format(Locale.US, "Activity resultCode was not OK, it was %d, and requestCode is %d", resultCode, requestCode);
Log.w("MyTag", msg);
}
}