简体   繁体   English

从Android中的图库加载图像

[英]Load an Image from the Gallery in Android

I'm currently doing a Widget in Android. 我目前正在Android中做一个Widget。 It is on the market and it's free. 它在市场上并且是免费的。 I want to surprise the users by let them choose a picture they want to show in the widget. 我想通过让用户选择他们想要在小部件中显示的图片来让用户感到惊讶。

Now... 现在...

If the widget is clicked, a PreferenceActivity appears. 如果单击窗口小部件,则会显示PreferenceActivity。 <-- Works! < - 作品!

In this Activity the user should be able to choose a picture from the phone picture gallery. 在此活动中,用户应该能够从手机图片库中选择一张图片。 <-- HOWTO? < - HOWTO?

After the User selected the prefered picture, the picture path or the drawable object should be stored in the SharedPreferences. 用户选择了首选图片后,图片路径或可绘制对象应存储在SharedPreferences中。 <-- Would be really nice! < - 真的很棒!

Is there any solution? 有什么解决方案吗?

Thx! 谢谢!

In order to get an image from the Gallery, you must send an intent to start up the Gallery for the user to choose an image as such 要从图库中获取图像,您必须发送启动图库的意图,以便用户选择图像

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
intent.setType("image/*");
startActivityForResult(intent, 10);

This will start the gallery and will call onActivityResult within your activity. 这将启动图库,并在您的活动中调用onActivityResult

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM