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.ContentValues;
import android.content.Context;

import android.net.Uri;

import android.provider.MediaStore.Images.Media;

public class Main {
    public static void insertImage2MediaStore(Context context, String path) {
        File f = new File(path);
        if (f != null && f.exists()) {
            ContentValues values = new ContentValues();
            values.put(Media.DISPLAY_NAME, f.getName());
            values.put(Media.DESCRIPTION, f.getName());
            values.put(Media.MIME_TYPE, "image/jpeg");
            values.put(Media.DATA, path);

            Uri uri = context.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
        }
    }
}