how to use photo taken by the application? - android

I have an Android application, which takes a photo if you hit a button:
#Override
public void onClick(View view) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
view.getContext().startActivity(intent);
}
How can I use the picture and load it into an existing ImageView? (It should overwrite the default picture)
Thank you for your help :)

Related

How do I take a picture on Android app, and save photo to gallery in internal storage? (Not SD Card)

I have my app so I have the ability to open the camera and take a picture, the app then shows me a preview of the photo just taken, and when I press 'OK', it is gone. I want to be able to save the image I have taken to my internal storage on my phone, (and possibly have a function so I can access my gallery and preview it later on). I have searched everywhere but all the help I am getting is to store it on an SD card, whereas I want to use my phones built in storage. Thank you
My code so far:
Button butCamera;
ImageView imageView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
butCamera = (Button) findViewById(R.id.butCamera);
imageView = (ImageView) findViewById(R.id.imageView);
butCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent (MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);
}
});
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
imageView.setImageBitmap(bitmap);
}
What you are trying to achieve is quite complex,
an i'm not sure you could use this common storage method to achieve it
File root = Environment.getExternalStorageDirectory();
But have a loot at this post, it should have what you require
android - save image into gallery
To store the Image to Internal storage of the device, you will have to do something like this.
File file = new File(Environment.getExternalStorageDirectory(), "MyFile.jpg");
Uri uri = Uri.fromFile(file);
intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
startActivityForResult(intent, CAMERA_REQUEST);

android show image in default gallery viewer

I am loading some images into my activity using an AsyncTask as clickable images. On click I need to open that image in the default image viewer of the android. I am new to android. Can any one please help. My code looks like
ImageView image = new ImageView(this);
String ed="http://www.domain.com/image.jpg";
image.setTag(ed);
DownloadImagesTask td=new DownloadImagesTask(this);
td.execute(image);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.v("TAGG","sdsd");
}
});
Please help me.
Gallery application does not accept URL for an image as part of the Intent. You need to save the image first. Then you can launch the default image viewer with something like this:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

Android - Show image from resource drawable

I'm new at Android apps and I'm working on a project started by a friend of mine. The code below is from a class that loads a view that has a small image with some text around it.
I want the image to appear fullscreen (on the standard Android image viewer) when I click on the thumbnail.
I tried several different solutions, and none of them worked.
This example throws the following exception:
E/AndroidRuntime(13768): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=android.resource://com.app.mid/2130837533 typ=image/png }
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view_n1);
ImageView img = (ImageView) findViewById(imageResource);
img.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("android.resource://com.app.mid/" + R.drawable.p_page_11_image_0001), "image/png");
startActivity(intent);
}
});
}
The images are inside the drawable folder (..\res\drawable-xhdpi). I'm using Eclipse ADT and I configured it to run on my Galaxy Nexus.
Again, I tried several solutions with no luck. Any thoughts?
Thanks
Try to use Intent.ACTION_VIEW instead of android.content.Intent.ACTION_VIEW
Intent i = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(yourUri, "image/png");
startActivity(intent);

Get Location of Saved Camera Picture

Okay, so I have an onclick on a button that opens the camera, when I take a picture and save it how do I get the file name+location of where it was saved to open it in my app?
Here is my button click
Button btncamera = (Button)findViewById(R.id.btncamera);
btncamera.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent cameraIntent = nwe Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 2500);
}
}
Here is my Result it doesn't contain anything, but it will start another Intent to display the image:
protected void onActivityResult(int requestCode, int resultCode, Intent data){
}
Maybe I am doing it wrong, but any guidance would be much appreciated thanks!
Try adding this to your onActivityResult.
Bitmap picture = (Bitmap) data.getExtras().get("data");
Take the image out of the camera intent, create a bitmap out of it, and then use it from there. Write it to a file, or import it directly into a display resource.
Also be sure to check your ResultCode to determine if a picture actually has been taken.

How can ImageView link to web page?

is it possible to make an imageview link to a web page such that when user taps on the image, it takes them to a web page?
Just add a click listener to the image to open an URL:
ImageView img = (ImageView)findViewById(R.id.foo_bar);
img.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse("http://casidiablo.net"));
startActivity(intent);
}
});
That's truly possible, at onClick handler you need to start an activity with intent specifying the uri. See How to open default browser for example.
another method we can even use is
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent redirect2=new Intent(getApplicationContext(),RedirectAct.class);
startActivity(redirect2);
}
});

Categories

Resources