-1

Okay, so i'm very new to this android development. I have a button. i want this button to open the pick image from... kinda activity so the user can pick image from system or different gallery apps he has or camera or web. like other apps who do so. I want that the image selected will get the image id and store it to a database, and display the image as the button. I will do the storing, but how do i get image ID? and all the other stuff? thanks alot for anyone who helps me! Cheers!

Add request code:

public class add_requests extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.add_requests);
}
Globals mThumbIds = Globals.getInstance();
public void onSaveClick(View view){
    EditText desc = (EditText) findViewById(R.id.request_name);
    EditText message = (EditText) findViewById(R.id.request_message);
    String message1 = message.getText().toString();
    String desc1 = desc.getText().toString();
    Request r1 = new Request(R.drawable.iphone, message1,desc1);
    mThumbIds.getData().add(r1);
    finish();
}
public void browsePictures(){
    Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI);

}

}

1 Answers1

0

Following is sample to pick and use picture from Gallery.

public void pickImage() {
  Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
  intent.setType("image/*");
  startActivityForResult(intent, PICK_PHOTO_FOR_AVATAR);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PICK_PHOTO_FOR_AVATAR && resultCode == Activity.RESULT_OK) {
        if (data == null) {
            //Display an error
            return;
        }
        InputStream inputStream = context.getContentResolver().openInputStream(data.getData());
        //Now you can do whatever you want with your inpustream, save it as file, upload to a server, decode a bitmap...
    }
}
Waqar Khan
  • 468
  • 4
  • 18