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
  • 相关阅读:
    mysql免安装使用(win7 64位系统)
    [NOIP2011]瑞士轮
    [NOIP2011]数的划分
    [洛谷2994]超级弹珠
    并查集
    [codevs1073]家族
    快速幂
    [NOI2002]银河英雄传说
    [NOIP2007]矩阵取数游戏
    [洛谷2415]集合求和
  • 原文地址:https://www.cnblogs.com/wucaiyun1/p/4933049.html
Copyright © 2011-2022 走看看