Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.ContentResolver;
import android.content.Context;

import android.database.Cursor;

import android.provider.MediaStore.Images;

import android.util.Log;
import java.io.File;

public class Main {
    public static String checkNull(Context context, int lastImageId, File fileCapture) {
        final String[] imageColumns = { Images.Media._ID, Images.Media.DATA };
        final String imageOrderBy = Images.Media._ID + " DESC";
        final String imageWhere = Images.Media._ID + ">?";
        final String[] imageArguments = { Integer.toString(lastImageId) };

        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = contentResolver.query(Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere,
                imageArguments, imageOrderBy);
        if (cursor == null)
            return null;

        String newpath = null;
        if (cursor.getCount() >= 2) {
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                int id = cursor.getInt(cursor.getColumnIndex(Images.Media._ID));
                String data = cursor.getString(cursor.getColumnIndex(Images.Media.DATA));
                if (data.equals(fileCapture.getPath())) {
                    int rows = contentResolver.delete(Images.Media.EXTERNAL_CONTENT_URI, Images.Media._ID + "=?",
                            new String[] { Long.toString(id) });
                    boolean ok = fileCapture.delete();

                } else {
                    newpath = data;
                }
            }
        } else {
            newpath = fileCapture.getPath();
            Log.e("MediaUtils", "Not found duplicate.");
        }

        cursor.close();
        return newpath;
    }
}