View

Wednesday, 13 April 2011

Click the Button and open Image Gallery


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class tuesdayAppli extends Activity {
    private static final int SELECT_PICTURE = 1;
/** Called when the activity is first created. */
Button button1;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
      
        button1=(Button)findViewById(R.id.button1);
        button1.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
    }
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          switch(requestCode) {
          case SELECT_PICTURE: // our request code
           if(resultCode == Activity.RESULT_OK)
           { // result was ok
           Uri selectedImage = data.getData();
           Intent i = new Intent(getApplicationContext(),ImageView.class);

               // ----------------- Problem Area -----------------
               // I would like to send the filename to the Intent object, and send it over.
               // However, the selectedImage.toString() method will return a
               // "content://" string instead of a file location.  How do I get a file
               // location from that URI object?
               i.putExtra("PICTURE_LOCATION", selectedImage.toString());

               // Start the activity outlined with the Intent above:
               startActivity(i);
           }
  }
              
            }  
  
 
}



4 comments:

  1. hi saga,

    could u pls give me ur email address??

    is this image gallery taking images from net??

    where did u specify the url path??

    thanks

    ReplyDelete
  2. I simply want to say I’m very new to blogs and actually loved you’re blog site. Almost certainly I’m going to bookmark your blog post . You absolutely come with great well written articles. Thanks a lot for sharing your blog.
    android development course fees in chennai | android app development training in chennai|Android Training institute in chennai with placement

    ReplyDelete