0

so I am (slowly!!) getting the hang of android, but the following is confusing me;

I want to open a specific image file when the user clicks on an image button, i am using this code:

 Intent showchart = new Intent(); 
 showchart.setAction(Intent.ACTION_VIEW);
 showchart.setDataAndType(Uri.parse("file:///sdcard/1m.jpg"), "image/*");
 startActivity(showchart);

and it is working fine. I would like to be able to swipe as per the gallery app to the next image without having to go back to my app, but it is not working, even though there are lots of images in the directory.

Help well received!

===================edit===================================================

i found this code from google that seems closer to what i need, but how should i modify it to oen just the one file i want?

TextView textTargetUri;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Button buttonLoadImage = (Button)findViewById(R.id.loadimage);
  textTargetUri = (TextView)findViewById(R.id.targeturi);

  buttonLoadImage.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
 // TODO Auto-generated method stub
 Intent intent = new Intent(Intent.ACTION_PICK,
 android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
 startActivityForResult(intent, 0);
 }});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);

if (resultCode == RESULT_OK){
Uri targetUri = data.getData();
textTargetUri.setText(targetUri.toString());
}
  }
   }

i have not come across the result ok / onactivity result stuff before, im guessing i should be able to edit that textview to the path i want and update the string to reflect a value loaded when the user clicks one of my imagebuttons?

andy
  • 391
  • 13
  • 33

1 Answers1

0

What is understood is you are trying to open a galley from your app and selecting an image. Check out this link, it could be a lot of help.

Get/pick an image from Android's built-in Gallery app programmatically

Community
  • 1
  • 1
Robin Chander
  • 7,225
  • 3
  • 28
  • 42
  • maybe, but that link seems to have a huge amount more code for what seems a simple request. have i missed something? – andy Nov 06 '12 at 20:09