hello !! i'm a newbie in android....and now i'm developing an app. its
kind of extension of Notepad android app.. i would like to know how to
add images from the sd card and camera images to the app and add notes
to them and store it... right now i have the notepad app developed
using the tutorial in android developer site...now i am able to access
the images in the sd card.
if i pick an image... sometimes the app crashes and sometimes the
gallery returns empty space in the imageview.
my code goes like this...
noteEdit.java
public class NoteEdit extends Activity {
private static final int SELECT_PIC = 0;
private static final int SELECT_PHOTO = 0;
private EditText mTitleText;
private EditText mBodyText;
private Long mRowId;
private ImageView imageView;
private String selectedImagePath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.note_edit);
setTitle(R.string.edit_note);
mTitleText = (EditText) findViewById(R.id.title);
mBodyText = (EditText) findViewById(R.id.body);
imageView = (ImageView)findViewById(R.id.img);
Button confirmButton = (Button) findViewById(R.id.confirm);
mRowId = null;
Bundle extras = getIntent().getExtras();
if (extras != null) {
String title = extras.getString(NotesDbAdapter.KEY_TITLE);
String body = extras.getString(NotesDbAdapter.KEY_BODY);
mRowId = extras.getLong(NotesDbAdapter.KEY_ROWID);
if (title != null) {
mTitleText.setText(title);
}
if (body != null) {
mBodyText.setText(body);
}
}
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Bundle bundle = new Bundle();
bundle.putString(NotesDbAdapter.KEY_TITLE,
mTitleText.getText().toString());
bundle.putString(NotesDbAdapter.KEY_BODY,
mBodyText.getText().toString());
if (mRowId != null) {
bundle.putLong(NotesDbAdapter.KEY_ROWID, mRowId);
}
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, SELECT_PIC, 0, R.string.insert_img);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case SELECT_PIC:
Toast.makeText(this, "SELECT PIC",
Toast.LENGTH_LONG).show();
Intent photoPickerIntent = new
Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(Intent.createChooser(photoPickerIntent,"Select
Picture"), SELECT_PHOTO);
return true;
}
return super.onMenuItemSelected(featureId, item);
}
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SELECT_PHOTO) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
System.out.println("Image Path : " + selectedImagePath);
imageView.setImageURI(selectedImageUri);
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null,
null);
int column_index =
cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}}
i dont know where i have gone wrong
any kind of help would be helpful..
Thank you :)
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en