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 8288467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:17:22+00:00 2026-06-08T12:17:22+00:00

I am trying to make a browse button, for the user to select an

  • 0

I am trying to make a browse button, for the user to select an image. I use the following code:

void BrowseButton_Click(object sender, EventArgs e)
{
    Intent intent = new Intent(); intent.SetType("image/*");
    intent.SetAction(Intent.ActionGetContent);
    StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), 1);
}

protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);

    if (resultCode == Result.Ok && requestCode == 1)
    {
        ImageView imageView = FindViewById<ImageView>(Resource.Id.MainimageView);
        Android.Net.Uri selectedImageUri = data.Data;
        var bitmap = MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
        SherarClass.Uri = getRealPathFromURI(data.Data);
        BitmapDrawable dd = new BitmapDrawable(bitmap);
        imageView.SetImageDrawable(dd);
        bitmap.Dispose();
    }
}

It works the first and the second time after that it throws an Java.Long.Error exception.

stack trace :

     at Android.Runtime.JNIEnv.CallStaticObjectMethod (IntPtr jclass, IntPtr jmethod,     Android.Runtime.JValue[] parms) [0x00000] in <filename unknown>:0 
     at Android.Provider.MediaStore+Images+Media.GetBitmap    (Android.Content.ContentResolver cr, Android.Net.Uri url) [0x00000] in <filename unknown>:0 
     at Scannet.Activity1.OnActivityResult (Int32 requestCode, Result resultCode,    Android.Content.Intent data) [0x00000] in <filename unknown>:0 
 --- End of managed exception stack trace ---
     java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:556)
at android.provider.MediaStore$Images$Media.getBitmap(MediaStore.java:706)
at scannet.Activity1.n_onActivityResult(Native Method)
at scannet.Activity1.onActivityResult(Activity1.java:37)
at android.app.Activity.dispatchActivityResult(Activity.java:4649)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2996)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3043)
at android.app.ActivityThread.access$1100(ActivityThread.java:127)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1188)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4441)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
  • 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-08T12:17:23+00:00Added an answer on June 8, 2026 at 12:17 pm
    void BrowseButton_Click(object sender, EventArgs e)
     {
       Intent intent = new Intent(); intent.SetType("image/*");
       intent.SetAction(Intent.ActionGetContent);
       StartActivityForResult(Intent.CreateChooser(intent, "Select Picture"), 1);
     }
    
    
    protected override void OnActivityResult(int requestCode, Result resultCode,     Android.Content.Intent data)
    {
      base.OnActivityResult(requestCode, resultCode, data);
    
    if (resultCode == Result.Ok && requestCode == 1)
    {
       ImageView imageView = FindViewById<ImageView>(Resource.Id.MainimageView);
       Android.Net.Uri selectedImageUri = data.Data;
       BitmapFactory.Options op = new BitmapFactory.Options();
       op.InSampleSize = 2;
       SherarClass.Uri = getRealPathFromURI(data.Data);
       using (Bitmap bitmap = BitmapFactory.DecodeFile(SherarClass.Uri, op))
       {
           imageView.SetImageBitmap(bitmap);
           GC.Collect();
       }
    }
    

    }

        public String getRealPathFromURI(Android.Net.Uri contentUri)
        {
            String[] projection = new String[] {Android.Provider.MediaStore.MediaColumnsConsts.Data };
            ContentResolver cr = this.ContentResolver;
            Android.Database.ICursor cursor = cr.Query(contentUri, projection,null, null, null);
            if (cursor != null && cursor.Count > 0)
            {
                cursor.MoveToFirst();
                int index =cursor.GetColumnIndex(Android.Provider.MediaStore.MediaColumnsConsts.Data);
                return cursor.GetString(index);
            }
            return null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Flex 4, I am trying to make a simple browse button update the
I'm trying make a login window where a user is prompted to enter their
Trying to make an xna game, where the user needs to tap to stop
I'm trying to make an image database which does not keep a consistent record
I'm trying to make test-program that opens a website by pushing a button. I
I'm trying to validate text and I use an alert() to let the user
I'm trying to solve the following problem: I have a download button that when
I'm trying to setup a button on a map that allows a user to
I am trying to make a radio input checked. Neither of the following works:
Well, I'm trying to make ASP.NET urls looking user-friendly, like it was explained in

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.