zoukankan      html  css  js  c++  java
  • Allow user to select camera or gallery for image

    Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    Intent gallIntent=new Intent(Intent.ACTION_GET_CONTENT);
    gallIntent.setType("image/*"); 
    Intent camIntent = new Intent("android.media.action.IMAGE_CAPTURE");
    pickIntent.putExtra(Intent.EXTRA_INTENT, camIntent);
    pickIntent.putExtra(Intent.EXTRA_INTENT, gallIntent)
    pickIntent.putExtra(Intent.EXTRA_TITLE, "Select Source");
    startActivityForResult(pickIntent, IMAGE_SELECTOR); 

    以下为参考代码: 

    AlertDialog.Builder getImageFrom = new AlertDialog.Builder(Fotos.this);

                    getImageFrom.setTitle("Select:");
                    final CharSequence[] opsChars = {getResources().getString(R.string.takepic), getResources().getString(R.string.opengallery)};
                    getImageFrom.setItems(opsChars, new android.content.DialogInterface.OnClickListener(){
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if(which == 0){
                                Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                                startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
                            }else
                                if(which == 1){
                                    Intent intent = new Intent();
                                    intent.setType("image/*");
                                    intent.setAction(Intent.ACTION_GET_CONTENT);
                                    startActivityForResult(Intent.createChooser(intent,
                                        getResources().getString(R.string.pickgallery)), SELECT_PICTURE);
                                }
                            dialog.dismiss();
                        }
                    });
  • 相关阅读:
    python3线程介绍01(如何启动和调用线程)
    CentOS7 设置静态 ip
    png2ico
    Thunderbird 配置 QQ mail
    memcached 开机启动 (Ubuntu)
    CentOS7 docker 安装的 container-selinux 问题及解决
    YAML 的基本语法
    docker 的脚本化安装和使用
    解决Windows下 “setup.py build” 时出现错误 ” error: Unable to find vcvarsall.bat”
    Electric Fence
  • 原文地址:https://www.cnblogs.com/top5/p/2353733.html
Copyright © 2011-2022 走看看