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
  • 相关阅读:
    继承实战
    工厂设计模式
    接口匿名内部类
    枚举类
    接口.匿名内部类
    学生信息管理系统(bug)
    System类
    1.1 计算机基础知识 & jdk 安装 & 标识符
    DedeCMS 在子栏目或内容页,调用所在顶级栏目的栏目名
    latex 中 section 标题中如何插入特殊符号
  • 原文地址:https://www.cnblogs.com/wucaiyun1/p/4933049.html
Copyright © 2011-2022 走看看