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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM