Help Regarding building Camera App

All your problems with Audio, Video and Images.

Help Regarding building Camera App

Postby vipulshah2010 » Mon Mar 08, 2010 11:39 am

I m developing a simple app which is regarding camera but the problem is when i capture snap
sometimes it works.but sometimes just black screen comes.
so rather now i have decided to use android inbuilt camera intent to use in my app.rather than coding the camera functionality.but since i m new to android i dont know exactly how to do it.
can somebody please give me a source code.
so that i can snap a picture and save it on sd card.
thnx in advance. :)
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Top

I have got something

Postby vipulshah2010 » Mon Mar 08, 2010 11:43 am

Intent intent2= new Intent("android.media.action.IMAGE_CAPTURE");

one of my friend suggested me to use above code to call inbuilt cam.
but don't know exactly how to do it.
i written that code in my app.
but it just displays the camera preview window.
but how should i tell it when button is clicked save the image to desired location.
someone please help me.
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Postby Boni2k » Mon Mar 08, 2010 11:52 am

Google: http://slexy.org/view/s21IlM6tzB
So basically it's

Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
this.startActivityForResult(i,REQUEST_CAMERA) ;

and an onResult method. Please note that you probably only get a small sized picture with this code. If you want to have the full sized picture you need to put an intent extra to your intent in order to save the big picture to your SD card. Search Google for how to do this.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

I Probably Got The Solution

Postby vipulshah2010 » Tue Mar 09, 2010 8:54 am

[syntax="java"]
package org.PUP;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;

public class Cam extends Activity
{
static String FilePath;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 1);
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==1)
{
Bitmap x = (Bitmap) data.getExtras().get("data");
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
OutputStream outstream;
try
{
outstream = getContentResolver().openOutputStream(uri);
x.compress(Bitmap.CompressFormat.JPEG,70,outstream);
outstream.close();
}
catch (FileNotFoundException e)
{

}
catch (IOException e)
{

}
String [] proj={MediaStore.Images.Media.DATA};
final Cursor cursor = managedQuery(uri,
proj,
null,
null,
null);
int column_index= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
FilePath=cursor.getString(column_index);
Main.flag=2;
Intent in= new Intent(Cam.this,Gal.class);
startActivity(in);
}
}
}

I have got the above solution and its working fine and easily and correctly saving images to gallery.
but i just only want that after i click the camera capture button i want that image should directly get saved.
without clicking the done button.
i dont want the done button that comes after i click the capture button og camera.
Plz somebody gv me a solution.
thnx in advance. :)
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Postby Boni2k » Tue Mar 09, 2010 12:01 pm

You can't do that without building your own camera activity.
Boni2k
Experienced Developer
Experienced Developer
 
Posts: 88
Joined: Sun Dec 20, 2009 9:46 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 12 guests