欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

Android 实现IOS选择拍照相册底部弹出的实例

程序员文章站 2023-11-21 18:06:10
android 实现ios选择拍照相册底部弹出的实例 效果图 1. androidstudio使用 dependencies { compile...

android 实现ios选择拍照相册底部弹出的实例

效果图

Android 实现IOS选择拍照相册底部弹出的实例

1. androidstudio使用

dependencies {

  compile 'com.guoqi.widget:actionsheet:1.0'

}

2. 使用

//1.实现接口

 implements actionsheet.onactionsheetselected


//2.在某个点击事件中添加:
 actionsheet.showsheet(this, this, null);


//3.然后重写点击方法:
@override
  public void onclick(int whichbutton) {
    switch (whichbutton) {
      case actionsheet.choose_picture:
        //相册
        choosepic();
        break;
      case actionsheet.take_picture:
        //拍照
        takepic();
        break;
      case actionsheet.cancel:
        //取消
        break;
    }
  } 


//加入自己的逻辑
public void takepic(){
 string state = environment.getexternalstoragestate();
        if (state.equals(environment.media_mounted)) {
          intent intent = new intent(mediastore.action_image_capture);
          file outdir = environment.getexternalstoragepublicdirectory(environment.directory_pictures);
          if (!outdir.exists()) {
            outdir.mkdirs();
          }
          file outfile = new file(outdir, system.currenttimemillis() + ".jpg");
          picpath = outfile.getabsolutepath();
          intent.putextra(mediastore.extra_output, uri.fromfile(outfile));
          intent.putextra(mediastore.extra_video_quality, 1);
          startactivityforresult(intent, actionsheet.take_picture);
        } else {
          toast.maketext(this, "请确认已经插入sd卡", toast.length_short).show();
        }
}



//加入自己的逻辑
public void choosepic(){
  intent openalbumintent = new intent(intent.action_pick);
        openalbumintent.setdataandtype(mediastore.images.media.external_content_uri, "image/*");
        startactivityforresult(openalbumintent, actionsheet.choose_picture);
}



感谢阅读,希望能帮助到大家,谢谢大家对本站的支持,如有疑问请留言或者到本站社区交流讨论,大家共同进步!