Reputation: 143
Im developing a app which has a user sign-up activity, there I need to allow a user to add a profile picture to his profile at the sign-up phase and show the image in profile activity, How can I do that? Thanx
Upvotes: 1
Views: 2783
Reputation: 322
StartCamera is Button. When Button is pressed Camera will be started. Take Image and set your ImageView
as shown in below code:
startCamera.setOnClickListener(
new OnClickListener()
{
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Intent intent=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//intent.putExtra(MediaStore.EXTRA_OUTPUT,imageUri);
intent.putExtra("return-data", true);
startActivityForResult(intent,CAMERA_PIC_REQUEST);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode==Activity.RESULT_OK)
{
Bitmap bitmap=(Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
}
Upvotes: 1
Reputation: 575
I assume you will be allowing the user to select a profile picture from some location on the device, so try this:
Drawable d = Drawable.createFromPath(pathName);
Then just set that drawable as the source for an ImageView
Edit:
Launch an intent to find an image, this will allow the user to select where they want to pull the image from.
Intent imgIntent = new Intent(Intent.ACTION_GET_CONTENT);
imgIntent.setType("image/*");
startActivityForResult(imgIntent, 10);
In your activity you will need to override onActivityResult to handle the response.
Upvotes: 0