在我的应用程序中,单击图像按钮会将您带到画廊。单击图像后,我想调用onActivityResult
以存储图像路径,但它不起作用。在我的LogCat
它总是告诉我它在尝试保存图像路径时崩溃。
我的onActivityResult
方法:
mImageRowId = savedInstanceState != null ? savedInstanceState.getLong(ImageAdapter.KEY_ROWID) : null;
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PICK_FROM_FILE && data != null && data.getData() != null) {
Uri uri = data.getData();
if(uri != null) {
Cursor cursor = getContentResolver().query(uri, new String[] {
android.provider.MediaStore.Images.ImageColumns.DATA
}, null, null, null);
cursor.moveToFirst();
String image = cursor.getString(0);
cursor.close();
if(image != null) {
// HERE IS WHERE I WANT TO SAVE THE IMAGE. HERE MUST BE THE ERROR!
if (mImageRowId == null) {
long id = mImageHelper.createImage(image);
if (id > 0) {
mImageRowId = id;
}
}
// Set the image and display it in the edit activity
Bitmap bitmap = BitmapFactory.decodeFile(image);
mImageButton.setImageBitmap(bitmap);
}
}
}
}
这是我的onSaveInstanceState
方法:
private static final Long DEF_ROW_ID = 0L;
@Override
protected void onSaveInstanceState(Bundle outState) {
outState.putLong(ImageAdapter.KEY_ROWID, mImageRowId != null ? mImageRowId : DEF_ROW_ID);
super.onSaveInstanceState(outState);
}
这是我的一部分DbAdapter
:
public long createImage(String image) {
ContentValues cv = new ContentValues();
cv.put(KEY_IMAGE, image);
return mImageDb.insert(DATABASE_TABLE, null, cv);
}
你能找到问题吗?