Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:10:02+00:00 2026-06-03T08:10:02+00:00

I am android deveoper .i needed help that i try to take photo from

  • 0

I am android deveoper .i needed help that i try to take photo from camera and i get photo and how to add gallery view .how to possible? my code in below!!enter code here

Thanks!!

send_zoo_btn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            String base64string = "";
            // bitmap = i.getDrawingCache();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
            ImageByte = stream.toByteArray();
            base64string = Base64.encodeBytes(ImageByte);

            db.execSQL("insert into newanimal(path,selece_animal) values('"
                    + base64string + "','" + id + "' )");
            Toast.makeText(ThirdActivity.this, "Data inserted", 1).show();
            Intent intent = new Intent().setClass(ThirdActivity.this,
                    ZoobuzzActivity.class);
            startActivity(intent);
        }
    });
}

in below my onactivity result method in

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d("CheckStartActivity", "onActivityResult and resultCode = "
            + requestCode);
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == GALLERY || requestCode == CAMERA) {
        if (resultCode == RESULT_OK) {
            if (requestCode == CAMERA) {
                Log.d("log", " request code camera " + requestCode);
                final File file = getTempFile(this);
                try {
                    selImagePath = file.getAbsolutePath();
                    Log.v("anim", "path  " + selImagePath);

                    m_bmOCRBitmap = Media.getBitmap(getContentResolver(),
                            Uri.fromFile(file));

                    int calwidth;
                    int calheight;

                    // OI FILE Manager
                    FileOutputStream out;

                    out = new FileOutputStream(file);
                    int width = m_bmOCRBitmap.getWidth();
                    int height = m_bmOCRBitmap.getHeight();
                    if (width > height) {
                        calwidth = (int) ((width * 250) / height);
                        calheight = 250;
                    } else {
                        calheight = (int) ((height * 200) / width);
                        calwidth = 200;
                    }

                    bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap,
                            calwidth, calheight, true);

                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

                    Log.v("bitmap", " bitmap :" + bitmap);

                    img_pht.setImageBitmap(bitmap);

                    hideMenu();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();

                }
            } else if (requestCode == GALLERY) {

                Uri selectedImageUri = data.getData();

                Log.v("", " result code : " + resultCode + " request "
                        + requestCode + " data " + data);

                realpath = getPath(selectedImageUri);

                Log.v("anim", " realpath : " + realpath);
                file = new File(realpath);

                Log.v("anim", " file : " + file);

                m_bmOCRBitmap = BitmapFactory.decodeFile(realpath);
                int calwidth;
                int calheight;

                // OI FILE Manager
                FileOutputStream out;
                try {
                    out = new FileOutputStream(file);
                    int width = m_bmOCRBitmap.getWidth();
                    int height = m_bmOCRBitmap.getHeight();
                    if (width > height) {
                        calwidth = (int) ((width * 250) / height);
                        calheight = 250;
                    } else {
                        calheight = (int) ((height * 200) / width);
                        calwidth = 200;
                    }

                    bitmap = Bitmap.createScaledBitmap(m_bmOCRBitmap,
                            calwidth, calheight, true);

                    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);

                    Log.v("bitmap", " bitmap :" + bitmap);

                    img_pht.setImageBitmap(bitmap);
                    hideMenu();
                } catch (FileNotFoundException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
    }
    if (resultCode == 1) {
        Log.d("log", " request code di= " + requestCode);

        id = data.getExtras().getInt("id");
        if (GViewAdapter.imageIDs.get(id).equals("R.drawable")) {
            int as = Integer.parseInt("" + GViewAdapter.imageIDs.get(id));
            img_chose.setImageResource(as);
        } else {

        }

        Log.v("log", " id" + data.getExtras().getInt("id"));

    }

}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

private File getTempFile(Context context) {
    final File path = new File(Environment.getExternalStorageDirectory(),
            context.getPackageName());
    if (!path.exists()) {
        path.mkdir();
    }
    return new File(path, fileName);
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (!(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.DONUT)
            && keyCode == KeyEvent.KEYCODE_BACK
            && event.getRepeatCount() == 0) {
        onBackPressed();
    }
    return super.onKeyDown(keyCode, event);
}

public void onBackPressed() {
    if (isMenuVisible) {
        hideMenu();
    } else {
        finish();
    }
}

Error

05-02 11:26:35.900: ERROR/AndroidRuntime(510): FATAL EXCEPTION: main
05-02 11:26:35.900: ERROR/AndroidRuntime(510): java.lang.ArrayIndexOutOfBoundsException
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.zoobuzz.FirstActivity$1.onItemClick(FirstActivity.java:39)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.widget.Gallery.onSingleTapUp(Gallery.java:864)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.GestureDetector.onTouchEvent(GestureDetector.java:557)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.widget.Gallery.onTouchEvent(Gallery.java:839)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.View.dispatchTouchEvent(View.java:3766)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.app.Activity.dispatchTouchEvent(Activity.java:2086)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1655)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1785)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.os.Looper.loop(Looper.java:123)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at java.lang.reflect.Method.invokeNative(Native Method)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at java.lang.reflect.Method.invoke(Method.java:521)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-02 11:26:35.900: ERROR/AndroidRuntime(510):     at dalvik.system.NativeStart.main(Native Method)


enter code here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:10:03+00:00Added an answer on June 3, 2026 at 8:10 am

    Call the Camera Intent using

    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
    
    startActivityForResult(intent, PICK_IMAGE_FROM_CAMERA);
    
    
    
    @Override
    protected void onActivityResult(int requestCode , int resultCode ,
            Intent data) {
    
        // TODO Auto-generated method stub
    
    
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            switch (requestCode) {
                case PICK_IMAGE_FROM_CAMERA:
    
                    Uri uri = data.getData();
                    imageview.setImageURI(uri);
    
                    break;
    
    }
        }
    }
    

    To save image on SD Card on a specific Location

    if (uri != null) {
            String SD_Card_Path = Environment.getExternalStorageDirectory()
                    .toString();
            String Our_Path = SD_Card_Path + "/NewFolder/Images/";
            OutputStream fOut = null;
            ImageFullName = Image_Name + "_" + System.currentTimeMillis()
                    + ".jpg";
            File file = new File(Our_Path + ImageFullName);
            try {
                fOut = new FileOutputStream(file);
    
                Bitmap mBitmap = null;
                mBitmap = Media.getBitmap(this.getContentResolver(),
                        myCaptureUri);
    
                mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
                fOut.flush();
                fOut.close();
            }
            catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there something in the Android developer guidelines that disuades developers from providing the
Can someone please help me find a list of flags that are needed by
I am working on an Android app that displays photos which are downloaded from
Lint Error Checking tool that comes with Android Developer Tools has an optional setting
I got the following request from an Android developer : Would you change the
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/app/TextToSpeechActivity.html I was going to add this but how can i add it if
From: http://developer.android.com/resources/tutorials/views/hello-gridview.html , in ImageAdapter class: imageView.setLayoutParams(new GridView.LayoutParams(85, 85)); Look at the new GridView.LayoutParams
In android developer console, there is a point that licensing .What should i do?
void android.view.SurfaceHolder.setType(int type) public abstract void setType (int type) Since: API Level 1 This
On Android Developer Site has said that : We shouldn't use long operations work

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.