2

I want to set an imageview and let the user to set his own image, i found how to do that on another question, but all the answers contains attribute for startActivityForResult function like PICK_IMAGE or SELECT_IMAGE or ACTIVITY_IMAGE_SELECTOR but my eclipse says that those are not defined , why ?

Edit

Intent intent = new Intent();
            intent.setType("image/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(
                    Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
user user
  • 2,122
  • 6
  • 19
  • 24

2 Answers2

2

Declare this variable on top :

int PICK_IMAGE = 101;

This is just a request code to match on your activity result.

References :

Pick Image Intent

How To Pick Image From Gallery in Android App

Thanks.

Community
  • 1
  • 1
Pratik Sharma
  • 13,307
  • 5
  • 27
  • 37
1

in your MainActvity.java:

public class MainActivity extends Activity
{
   static MainActivity instance= null;
   protected void onCreate(Bundle savedInstanceState) 
   {
       super.onCreate(savedInstanceState);
       instance = this; 
    }
}

and in your class make:

MainActivity.instance.startActivityForResult(intent,request_code);
KhalidTaha
  • 453
  • 1
  • 5
  • 11