This article is mainly about getting pictures from gallery in Android
Design Project Layout
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context=". Mainactivity " > <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Selectimage"Android:text= "Select a picture" /> <ImageViewAndroid:id= "@+id/iv"Android:layout_width= "Fill_parent"Android:layout_height= "Fill_parent" /></LinearLayout>
Open the manifest file under Packages\apps\gallery and you can see that it contains the following code:
<ActivityAndroid:name= "Com.android.camera.ImageGallery"Android:label= "@string/gallery_label"android:configchanges= "Orientation|keyboardhidden"Android:icon= "@drawable/ic_launcher_gallery"> <Intent-filter> <ActionAndroid:name= "Android.intent.action.MAIN" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.VIEW" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <DataAndroid:mimetype= "Vnd.android.cursor.dir/image" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.VIEW" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <DataAndroid:mimetype= "Vnd.android.cursor.dir/video" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.GET_CONTENT" /> <categoryAndroid:name= "Android.intent.category.OPENABLE" /> <DataAndroid:mimetype= "Vnd.android.cursor.dir/image" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.GET_CONTENT" /> <categoryAndroid:name= "Android.intent.category.OPENABLE" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <DataAndroid:mimetype= "image/*" /> <DataAndroid:mimetype= "video/*" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.PICK" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <DataAndroid:mimetype= "image/*" /> <DataAndroid:mimetype= "video/*" /> </Intent-filter> <Intent-filter> <ActionAndroid:name= "Android.intent.action.PICK" /> <categoryAndroid:name= "Android.intent.category.DEFAULT" /> <DataAndroid:mimetype= "Vnd.android.cursor.dir/image" /> </Intent-filter> </Activity>
The logic section code is as follows:
Public classMainactivityextendsActivity {PrivateImageView IV; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); IV=(ImageView) Findviewbyid (R.ID.IV); } Public voidselectimage (view view) {//activating the application of the system library select a pictureIntent Intent =NewIntent (); Intent.setaction (Intent. Action_pick); Intent.settype ("Image/*"); Startactivityforresult (Intent,0); } @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { if(Data! =NULL) {URI Uri= Data.getdata ();//the URI path of the pictureIv.setimageuri (URI); } Super. Onactivityresult (Requestcode, ResultCode, data); }}
Android Get pictures from gallery