Android Get pictures from albums

Source: Internet
Author: User

Getting pictures from albums is one of the most used technologies in Android apps, but it's easy to use intent.

Just knocked on a dome before going to bed or sharing a bit

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 android:orientation= "vertical">6 7 8     <Button9         Android:layout_width= "Fill_parent"Ten Android:layout_height= "Wrap_content" One Android:text= "View" A Android:onclick= "Take" /> -     <ImageView -         Android:id= "@+id/im" the Android:layout_width= "Fill_parent" - Android:layout_height= "Fill_parent" /> -  - </LinearLayout>

The main view of Java code

Open the camera picture public void take (View v) {Intent Intent = new Intent (); intent.setaction (Intent.action_pick); Intent.settype (" Vnd.android.cursor.dir/image "); Startactivityforresult (intent, 200);} @Overrideprotected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult ( Requestcode, ResultCode, data); try {uri uri = Data.getdata (); Bitmap Bitmap = MediaStore.Images.Media.getBitmap (Getcontentresolver (), URI); Im.setimagebitmap (Bitmap);// Set to ImageView} catch (Exception e) {e.printstacktrace ();}}

And here's the next possible permission to

<uses-permission android:name= "Android.permission.CAMERA"/>

Android Get pictures from albums

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.