开发者

ActivityForResult To Only Get A JPEG

Hey everybody,

I'm writing a small social netw开发者_开发技巧orking app, and one of the features I included is the ability to upload a picture to a server to be used as your "profile picture". I did this by starting an ActivityForResult with this intent:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
System.out.println("STARTED IT HERE");
startActivityForResult(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE);

This lets the user choose between getting an image URI from whatever accepts this Intent (Gallery and Astro by me). I have code that handles everything, and it all works (other than an issue with an outOfMemoryException when I pick the image from the gallery, but that's for a different topic :) ). My question is, how can I say something like:

intent.setType("image/jpeg");

because I only want users to upload jpegs?

Thanks so much in advance!!!


You just want to limit people to picking jpg style files?

How about this?

Intent pickPhoto = new Intent(Intent.ACTION_PICK);
pickPhoto.setType("image/*.jpg");

Sorry had to edit, I copied the wrong two lines from my app. Went one line to high. This is what I meant.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜