user user
user user

Reputation: 2172

Android: can't find startActivityForResult request_code

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);

Upvotes: 2

Views: 1885

Answers (2)

Pratik Sharma
Pratik Sharma

Reputation: 13415

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.

Upvotes: 2

KhalidTaha
KhalidTaha

Reputation: 473

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);

Upvotes: 1

Related Questions