get Intent Uri - Android Intent

Android examples for Intent:Intent Bundle

Description

get Intent Uri

Demo Code


//package com.java2s;

import android.content.ContentResolver;

import android.database.Cursor;
import android.net.Uri;

import android.provider.MediaStore;
import java.io.File;

public class Main {
    private static final String[] PROJECTION = new String[] { MediaStore.MediaColumns.DATA };

    private static Uri getIntentUri(Uri takenPhotoUri, ContentResolver cr) {
        String path = getPhotoFilePath(takenPhotoUri, cr);
        if (path == null) {
            throw new IllegalStateException("Photo resolution failed");
        }/*from  w  w w . j  av a  2s  .  co m*/
        return Uri.fromFile(new File(path));
    }

    private static String getPhotoFilePath(Uri takenPhotoUri,
            ContentResolver cr) {
        Cursor cursor = cr.query(takenPhotoUri, PROJECTION, null, null,
                null);
        String res = null;
        if (cursor != null) {
            int dataIdx = cursor
                    .getColumnIndex(MediaStore.MediaColumns.DATA);
            if (dataIdx >= 0 && cursor.moveToFirst())
                res = cursor.getString(dataIdx);
            cursor.close();
        }
        return res;
    }
}

Related Tutorials