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

发布时间:2020-08-25 17:53:54 作者:gooqii
来源:脚本之家 阅读:252

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);
}



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

推荐阅读:
  1. react-native 封装选择弹出框示例(试用ios&android)
  2. Android工具类ImgUtil选择相机和系统相册的示例分析

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android ios 拍照

上一篇:C语言实现数独游戏的求解

下一篇:mysql的安装路径怎么查看

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》