我是Android的新手,当我尝试使用IsTrigger=false
时,我收到此错误。
这是代码
decodefile()
请告诉我我的错误。
答案 0 :(得分:0)
找到了这个答案
Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
intent.setType("image/*");
startActivityForResult(intent, SELECT_IMAGE);
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_IMAGE) {
try {
selectedImagePath = getAbsolutePath(intent.getData());
mImageCaptureUri = intent.getData();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public String getAbsolutePath(Uri uri) {
String[] projection = {MediaStore.MediaColumns.DATA};
@SuppressWarnings("deprecation")
Cursor cursor = managedQuery(uri, projection, null, null, null);
if (cursor != null) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} else
return null;
}
答案 1 :(得分:-1)
请试试。
int PICK_FROM_GALLERY = 3;
String path;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_FROM_GALLERY
&& resultCode == Activity.RESULT_OK) {
try {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
path = cursor.getString(columnIndex);
cursor.close();
} catch (NullPointerException e) {
}
}
}
public void pickFromGallery()
{
Intent i = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_FROM_GALLERY);
}