protected void saveTodo() { String imageString = null; if (mImageUrl != null && !mImageUrl.equals("")) { try { Cursor cursor = getContentResolver().query(mImageUrl, null, null, null, null); cursor.moveToFirst(); int index = cursor .getColumnIndex(MediaStore.Images.ImageColumns.DATA); String absoluteFilePath = cursor.getString(index); FileInputStream fis = new FileInputStream(absoluteFilePath); int bytesRead = 0; ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b = new byte[1024]; while ((bytesRead = fis.read(b)) != -1) { bos.write(b, 0, bytesRead); } byte[] bytes = bos.toByteArray(); imageString = Base64.encodeToString(bytes, Base64.DEFAULT); } catch (Exception ex) { ex.printStackTrace(); } } new SaveTodoTask(this).execute(mTxtTodoText.getText().toString(), imageString); }