我想创建一个这样的对话框:
当用户点击链接中给出的个人资料图片时,我需要创建对话框。目前我这样做
final CharSequence[] items = { "Gallery", "Camera", "Cancel" };
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
builder.setTitle("Add Photo!");
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Gallery")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File f = new File(android.os.Environment.getExternalStorageDirectory(), "temp1.jpg");
mImageCaptureUri = Uri.fromFile(f);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
startActivityForResult(intent, CAMERA_CODE);
} else if (items[item].equals("Camera")) {
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GALLERY_CODE);
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
我不知道该如何设计,请帮助我。
答案 0 :(得分:0)
有两种方法可以实现这一目标。
默认情况下,Android不会显示单次打开相机和图库的选项。但做一些技巧将有助于实现这一目标。
请参阅以下代码,该代码用于在单个默认对话框中显示相机和图库浏览选项。
// Picks Camera first.
final List<Intent> cameraIntents = new ArrayList<Intent>();
final Intent captureIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
final PackageManager packageManager = getPackageManager();
final List<ResolveInfo> listCam = packageManager.queryIntentActivities(
captureIntent, 0);
for (ResolveInfo res : listCam) {
final String packageName = res.activityInfo.packageName;
final Intent intent = new Intent(captureIntent);
intent.setComponent(new ComponentName(res.activityInfo.packageName,
res.activityInfo.name));
intent.setPackage(packageName);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
cameraIntents.add(intent);
}
final Intent galleryIntent = new Intent();
galleryIntent.setType("image/*");
galleryIntent.setAction(Intent.ACTION_PICK);
// Chooser of filesystem options.
final Intent chooserIntent = Intent.createChooser(galleryIntent,
"Select Image from");
// Add the camera options.
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
cameraIntents.toArray(new Parcelable[]{}));
startActivityForResult(chooserIntent, TAKE_PHOTO_CODE);
这里已经回答了相同类型的问题。 ! - &GT; queryIntentActivityOptions not working
希望这会对你有所帮助,