我对Intent有疑问,所以我正在从画廊中选择照片,我尝试使用startActivity(galleryIntent,0);
但总是得到错误说错误的第二个参数类型。发现:' int',必需:' android.os.Bundle'
这是我的代码
protected void showChoosePicDialog(){
AlertDialog.Builder builder = new AlertDialog.Builder(Profile.this);
builder.setTitle("Change Photo");
String[] items = {"Gallery"};
builder.setNegativeButton("Cancel", null);
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case CHOOSE_PICTURE:
Intent galleryIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivity(galleryIntent, 0);
break;
}
}
});
builder.create().show();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
try{
if (requestCode == 0 && resultCode == RESULT_OK && null != data){
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
assert cursor != null;
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
mediaPath = cursor.getString(columnIndex);
userImage.setImageBitmap(BitmapFactory.decodeFile(mediaPath));
cursor.close();
}else {
Toast.makeText(this, "You haven't pick Image", Toast.LENGTH_LONG).show();
}
}catch (Exception e){
Toast.makeText(this, "Something went wrong", Toast.LENGTH_LONG).show();
}
}
有人可以帮助我吗?
答案 0 :(得分:1)
抱歉,我在这里愚蠢而不是startActivity(galleryIntent,0);
肯定是startActivityForResult(galleryIntent, 0);