-3
我有意圖的問題,所以我正在做從圖庫中選擇照片,我嘗試使用startActivity(galleryIntent,0);
但總是有錯誤說錯誤的第二個參數類型。實測: '詮釋',要求: 'android.os.Bundle'Android startActivity(galleryIntent,0);在這裏得到錯誤
這裏是我的代碼
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();
}
}
有人能幫助我嗎?