ActivityForResult 仅获取 JPEG
大家好,
我正在编写一个小型社交网络应用程序,我包含的功能之一是能够将图片上传到服务器以用作您的“个人资料图片”。我通过启动 ActivityForResult 来实现此目的:
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);
这让用户可以选择从接受此 Intent 的任何内容(我的 Gallery 和 Astro)获取图像 URI。我有处理所有事情的代码,并且一切正常(除了当我从图库中选择图像时出现 outOfMemoryException 问题,但那是针对不同的主题:))。我的问题是,我该怎么说:
intent.setType("image/jpeg");
因为我只希望用户上传 jpeg?
非常感谢!
Hey everybody,
I'm writing a small social networking 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!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只是想限制人们选择 jpg 样式文件?
这个怎么样?
Intent pickPhoto = new Intent(Intent.ACTION_PICK);
pickPhoto.setType("image/*.jpg");
抱歉必须编辑,我从应用程序中复制了错误的两行。上升了一行至高位。这就是我的意思。
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.