Android開啟系統的Document文檔圖片選擇

來源:互聯網
上載者:User

標籤:

 

開啟Document UI 過濾圖片

    private void startAcitivty() {        Intent intent = new Intent();        intent.setAction("android.intent.action.GET_CONTENT");        intent.setType("image/*");        startActivityForResult(intent,1001);    }

 

 

        @Override    protected void onActivityResult(int req, int res, Intent intent) {        Log.d("onActivityResult","1:" + req);        Log.d("onActivityResult","2:" + res);        Log.d("onActivityResult","3:" + intent);        if (intent != null) {            String data = intent.getDataString();            try {                Log.d("onActivityResult","4:" + URLDecoder.decode(data, "UTF-8"));                queryImage(URLDecoder.decode(data, "UTF-8"));            } catch (UnsupportedEncodingException e) {                e.printStackTrace();            }        }            }

 

能夠得到圖片content uri

下面處理圖片資料 得到圖片PATH

    private void queryImage(String data) {        String _path="_data";        String _album="bucket_display_name";        int idx = data.lastIndexOf(":");        String id = null;        if (idx != -1) {            id = data.substring(idx + 1);        }        Log.d("onActivityResult","id:" + id);        Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, "_id=" + id, null, null);        if (cursor.moveToFirst()) {            String path=cursor.getString(cursor.getColumnIndex(_path));            String album=cursor.getString(cursor.getColumnIndex(_album));              Log.d("onActivityResult","path:" + path + "," + album);                        File f = new File(path);            if (f.exists()) {                Bitmap b = BitmapFactory.decodeFile(path);                imageView.setImageBitmap(b);            }                    }        cursor.close();    }

 

 

不同手機的文檔選取器介面都有所不同。

START u0 {act=android.intent.action.GET_CONTENT typ=image/* cmp=com.android.documentsui/.DocumentsActivity (has extras)} from pid 11910

 

Android開啟系統的Document文檔圖片選擇

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.