一个仿微信的Android图片选择组件。
运行效果:
使用说明:
Gradle
dependencies { compile 'me.iwf.photopicker:PhotoPicker:0.1.8' }
Pick Photo
PhotoPickerIntent intent = new PhotoPickerIntent(MainActivity.this); intent.setPhotoCount(9); intent.setShowCamera(true); startActivityForResult(intent, REQUEST_CODE);
Preview Photo
Intent intent = new Intent(mContext, PhotoPagerActivity.class); intent.putExtra(PhotoPagerActivity.EXTRA_CURRENT_ITEM, position); intent.putExtra(PhotoPagerActivity.EXTRA_PHOTOS, photoPaths); startActivityForResult(intent, REQUEST_CODE);
onActivityResult
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) { if (data != null) { ArrayList<String> photos = data.getStringArrayListExtra(PhotoPickerActivity.KEY_SELECTED_PHOTOS); } } }
manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android" > <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-feature android:name="android.hardware.camera" android:required="true" /> <application ... > ... <activity android:name="me.iwf.photopicker.PhotoPickerActivity" android:theme="@style/Theme.AppCompat.NoActionBar" /> <activity android:name="me.iwf.photopicker.PhotoPagerActivity" android:theme="@style/Theme.AppCompat.NoActionBar"/> </application> </manifest>