Bootstrap

Android选择图片并获取图片的path

选择图片

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(intent,REQUEST_GET_CONTENT_CODE);

获取图片的uri

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);
	if (resultCode != RESULT_OK) {
		return;
	}
    if (requestCode == 0) {
		Uri uri = data.getData();
		String realPathFromURI = Utils.getRealPathFromURI(this, uri);
    }
}

根据uri获取图片的真实路径

public static String getRealPathFromURI(Activity context, Uri uri) {
	String imagePath = null;
	String docId = DocumentsContract.getDocumentId(uri);
	String id = docId.split(":")[1];
	String selection = MediaStore.Images.Media._ID+"="+id;
	Uri externalContentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
	Cursor cursor = context.getContentResolver().query(externalContentUri,
		null,
		selection,
		null,
		null);
	if(cursor!=null){
		if(cursor.moveToFirst()){
			imagePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
		}
	}
	return imagePath;
}

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;