zoukankan      html  css  js  c++  java
  • Intent.ACTION_PICK

    在常见的Activity Action Intent常量中,ACTION_PICK  android.intent.action.PICK 是“选择数据”的意思,来简单的分享一下我知道的Intent.ACTION_PICK的一些用法:

    (一)、调用图库,获取所有本地图片: 
    Intent imageIntent = new Intent(Intent.ACTION_GET_CONTENT); 
     imageIntent.setType("image/*"); 
     startActivityForResult(imageIntent, PICK_CODE); //PICK_CODE是常量

    (二)、调用本地联系人: 
     Intent intent = new Intent(Intent.ACTION_PICK); 
     intent.setType(ContactsContract.Contacts.CONTENT_TYPE); 
     startActivityForResult(intent, PICK_CONTACT); 
    (三)、调用音乐,获取所有本地音乐文件: 
    Intent audioIntent = new Intent(Intent.ACTION_GET_CONTENT); 
    audioIntent.setType("audio/*"); 
    startActivityForResult(audioIntent, PICK_AUDIO); 
    (四)、调用视频,获取所有本地视频文件: 
    Intent videoIntent = new Intent(Intent.ACTION_GET_CONTENT); 
    videoIntent.setType("video/*"); 
    startActivityForResult(videoIntent, PICK_VIDEO)

    调用图库处理:

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
            if (requestCode==PICK_CODE) 
            {
                if (intent!=null) 
                {
                    Uri uri=intent.getData();
                    Cursor cursor=getContentResolver().query(uri, null, null,null, null);
                    cursor.moveToFirst();
                    int idx=cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
                    currentPhotoString=cursor.getString(idx);
                    cursor.close();
                    resizePhono();
                    ivPhoto.setImageBitmap(photoImg);
                    tvTip.setText("Click Detect==>");
                }
            }
            super.onActivityResult(requestCode, resultCode, intent);
        }
        /**
         * 压缩图片
         */
        private void resizePhono() {
            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inJustDecodeBounds=true;//仅仅加载图片
            BitmapFactory.decodeFile(currentPhotoString, options);
            double radio=Math.max(options.outWidth*1.0d/1024f, options.outHeight*1.0d/1024f);
            options.inSampleSize=(int) Math.ceil(radio);
            options.inJustDecodeBounds=false;
            photoImg=BitmapFactory.decodeFile(currentPhotoString,options);
        }
    onActivityResult
  • 相关阅读:
    0008_Python变量
    shiro Filter过滤器管理197
    oracle 将一个数据库(A)的表导入到另一个数据库197
    top命令使用197
    SpringBoot下载Excel文件,解决文件损坏问题197
    java元注解197
    Content-Type
    centos7 下修改网络配置
    mint 20 install NVIDIA driver for 3080 via run
    使用numpy rot90操作image后,opencv cv2.rectangle 报错
  • 原文地址:https://www.cnblogs.com/wucaiyun1/p/4933049.html
Copyright © 2011-2022 走看看