Using java Syntax Highlighting
- 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);
- }
- }
- }
Parsed in 0.015 seconds, using GeSHi 1.0.8.4
I have written the above code to take a snap using android inbuilt camera.
and its doing fine.
but the serious issue that i m facing is i have coded such that first my another screen
should open and after clicking the button on that screen i must come on this screen(i.e Camera)
but when i launch my app it directly shows this screen without showing my first screen.
but when i restart my mobile and run this code agin it shows that screen first and then this screen.
that is correct.that why sometimes after launching app it directly jumps to camera screen.
my friend suggested me that it is beacause camera activity may be running in background.but he is also not sure
then also i want any of your suggestion for avoiding this abnormal behavior of app.and how to kill that camera activity.
plz hlp
Thnx in Advance
