Delete contact image. - Android Account

Android examples for Account:Contact

Description

Delete contact image.

Demo Code

/**Copyright (c) 2013 Durgesh Trivedi

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.//from   www  . j  a v a 2 s . c  o  m

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Log;

public class Main{
    /**
     * Delete contact image.
     * 
     * @param fileUri
     *            <code>Uri</code> of file
     * @param bitmap
     *            <code>Bitmap</code> for file
     * @param context
     *            Android <code>Context</code>
     */
    public static void deleteContactImage(String contactinfo,
            Context context) {
        int deleted = 0;

        Uri contentUri = getContentUri(contactinfo);
        deleted = context.getContentResolver().delete(contentUri, null,
                null);
        if (-1 == deleted) {
            Log.w("File Canot be deleted ", "File " + contactinfo
                    + " cannot be found");
        }
    }
    /**
     * Gets content <code>Uri</code> of file
     * 
     * @param fileUri
     *            <code>Uri</code> of file
     * @return content <code>Uri</code>
     */
    private static Uri getContentUri(String filename) {
        return ContactIconProvider.BASE_URI.buildUpon()
                .appendQueryParameter("file", filename).build();
    }
}

Related Tutorials