get Photo from Intent - Android Intent

Android examples for Intent:Picture Pickup

Description

get Photo from Intent

Demo Code

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

public class Main {

  public static String getPhotoByIntent(Activity ac, Intent data) {
    String path = null;/*from w  ww .  j a  v  a  2s  .  c  o m*/
    if (data == null) {
      path = null;
    } else {
      String[] proj = { MediaStore.Images.Media.DATA };
      Uri originalUri = data.getData();
      Cursor cursor = ac.managedQuery(originalUri, proj, null, null, null);
      if (cursor != null) {
        int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        path = cursor.getString(column_index);
      }
    }
    return path;
  }
}

Related Tutorials