Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;
import android.content.Intent;
import android.database.Cursor;

import android.net.Uri;

import android.provider.MediaStore;

public class Main {
    public static String getFileFromStorage(Context context, Intent data) {
        Uri pickedImage = data.getData();
        String[] filePath = { MediaStore.Images.Media.DATA };
        String path = "";
        Cursor cursor = context.getContentResolver().query(pickedImage, filePath, null, null, null);
        if (cursor != null) {
            cursor.moveToFirst();
            path = cursor.getString(cursor.getColumnIndex(filePath[0]));
            cursor.close();
        }
        return path;
    }
}