• 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
  • 相关阅读:
    C语言I博客作业08
    作业7
    作业6
    作业5
    作业--4
    java基础学习--I/O流
    刷题记录--[CISCN2019 华北赛区 Day2 Web1]Hack World
    ADB测试Android真机
    sqli-labs通关笔记
    Tensorflow入门
  • 原文地址:https://www.cnblogs.com/wucaiyun1/p/4933049.html
Copyright © 2020-2023  润新知