我制作了这段代码:
Intent i=new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, SELECTED_PICTURE);
此代码只允许我从图库中选择一张图片。我想知道如何选择多张照片或专辑。我不想创建自己的画廊,我想使用智能手机的默认图库。
感谢。
答案 0 :(得分:0)
您可以通过标准方式从API 18开始,使用下一个代码
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case SELECTED_PICTURE:
if (resultCode != Activity.RESULT_OK) return;
Uri dataUri = data.getData();
if (null != dataUri) {
processDataUri(dataUri);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ClipData clipData = data.getClipData();
if (null == clipData) return;
for (int i = 0; i < clipData.getItemCount(); i++) {
Uri clipDataUri = clipData.getItemAt(i).getUri();
processDataUri(clipDataUri);
}
processClipData(data.getClipData());
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
private void processDataUri(Uri uri) {
InputStream inputStream = null;
try {
inputStream = getActivity().getContentResolver().openInputStream(uri);
// read/copy/etc.
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (null != inputStream) try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
的更多详情
更新:处理结果
import java.util.Comparator;
import java.util.PriorityQueue;
public class HelloWorld
{
static class PQsort implements Comparator<Integer>
{
public int compare(Integer a, Integer b)
{
return Integer.compare(a, b);
}
}
public static void main(String[] args)
{
int[] ia = { 1, 10, 5, 3, 4, 7, 6, 9, 8 };
PQsort pqs = new PQsort();
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(11,pqs);
for (int x : ia)
{
pq.offer(x);
}
System.out.println("pq: " + pq);
}
}