返回顶部

收藏

Android 图片选择器

更多

AndroidImageSelector

Demo

####EnglishDoc

DownloadApk

使用说明

步骤一:

在Gradle中应用imageselector依赖

dependencies{
    compile'com.android.support:appcompat-v7:22.2.1'
    compile'com.android.support:support-v4:22.2.1'

    compile'com.yancy.imageselector:imageselector:1.0.0'

}

步骤二:

AndroidManifest.xml中添加如下权限

<!--从sdcard中读取数据的权限-->
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!--往sdcard中写入数据的权限-->
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!--在sdcard中创建/删除文件的权限-->
<uses-permissionandroid:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

AndroidManifest.xmlapplication节点下 添加以下Activity

<activity
  android:name="com.yancy.imageselector.ImageSelectorActivity"
  android:configChanges="orientation|screenSize"/>

步骤三:

将以下代码添加到您需要跳转的位置中

privatestaticintREQUEST_IMAGE=1;

  Intentintent=newIntent(MainActivity.this,ImageSelectorActivity.class); 

  intent.putExtra(ImageSelectorActivity.EXTRA_SHOW_CAMERA,true);  //是否开启相机 默认开启

  intent.putExtra(ImageSelectorActivity.EXTRA_SELECT_COUNT,9);   // 如果开启多选,则配置可选图片的最大数量默认9张

  /**
   *配置模式
   *单选 :  ImageSelectorActivity.MODE_SINGLE
   *多选 :  ImageSelectorActivity.MODE_MULTI
   */
  intent.putExtra(ImageSelectorActivity.EXTRA_SELECT_MODE,ImageSelectorActivity.MODE_MULTI);  //多选

  startActivityForResult(intent,REQUEST_IMAGE);

onActivityResult中获取选中的照片路径数组:

  @Override
  protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
    super.onActivityResult(requestCode,resultCode,data);
    if(requestCode==REQUEST_IMAGE&amp;&amp;resultCode==RESULT_OK&amp;&amp;data!=null){

      //GetImagePathList
      List<String>pathList=data.getStringArrayListExtra(ImageSelectorActivity.EXTRA_RESULT);

      for(Stringpath:pathList){
        Log.i("ImagePathList",path);
      }

    }
  }

代码示例

====

Thanks

-Glide

Aboutme

IamastudentinmainlandChina.IloveGoogle,loveAndroid,loveeverythingthatisinteresting.Ifyougetanyproblemswhenusingthislibraryoryouhaveaninternshipopportunity,pleasefeelfreetoemailmeif(t[e].getAttribute('data-cfhash'))return t[e]}();if(t&&(c=t.previousSibling)){p=t.parentNode;if(a=c.getAttribute('data-cfemail')){for(e='',r='0x'+a.substr(0,2)|0,n=2;a.length-n;n+=2)e+='%'+('0'+('0x'+a.substr(n,2)^r).toString(16)).slice(-2);p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)}p.removeChild(t)}}catch(u){}}()/ ]]> /).:smiley:

标签:java

收藏

0人收藏

支持

0

反对

0

发表评论