Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

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 FromCameraResult(Intent data, Context context, File file) {
        try {
            if (file != null) {
                Uri u = Uri.parse(MediaStore.Images.Media.insertImage(context.getContentResolver(),
                        file.getAbsolutePath(), null, null));
                return getPathFromUri(context, u);
            }
        } catch (Exception e) {
            return null;
        }
        return null;
    }

    public static String getPathFromUri(Context context, Uri u) {
        String[] pojo = { MediaStore.Images.Media.DATA };
        Cursor cursor = context.getContentResolver().query(u, pojo, null, null, null);
        String picPath = null;
        if (cursor != null) {
            int columnIndex = cursor.getColumnIndexOrThrow(pojo[0]);
            cursor.moveToFirst();
            picPath = cursor.getString(columnIndex);
            return picPath;
        }
        return null;
    }
}