Java tutorial
//package com.java2s; // Use of this source code is governed by a BSD-style license that can be import android.content.ContentResolver; import android.content.Context; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.util.Log; import java.io.FileNotFoundException; public class Main { private static final String TAG = "ContentUriUtils"; /** * Helper method to open a content URI and returns the ParcelFileDescriptor. * * @param context {@link Context} in interest. * @param uriString the content URI to open. * @return ParcelFileDescriptor of the content URI, or NULL if the file does not exist. */ private static ParcelFileDescriptor getParcelFileDescriptor(Context context, String uriString) { ContentResolver resolver = context.getContentResolver(); Uri uri = Uri.parse(uriString); ParcelFileDescriptor pfd = null; try { pfd = resolver.openFileDescriptor(uri, "r"); } catch (FileNotFoundException e) { Log.w(TAG, "Cannot find content uri: " + uriString, e); } catch (SecurityException e) { Log.w(TAG, "Cannot open content uri: " + uriString, e); } catch (IllegalArgumentException e) { Log.w(TAG, "Unknown content uri: " + uriString, e); } catch (IllegalStateException e) { Log.w(TAG, "Unknown content uri: " + uriString, e); } return pfd; } }