private void DeleteImage (String imgpath) {
Contentresolver resolver = Getcontentresolver ();
cursor cursor = MediaStore.Images.Media.query (resolver, MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
New string[]{mediastore.images.media._id}, MediaStore.Images.Media.DATA + "=?",
New String[]{imgpath}, NULL);
Boolean result = false;
URI uri = null;
if (Cursor.movetofirst ()) {
Long id = cursor.getlong (0);
Uri Contenturi = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
URI = Contenturis.withappendedid (Contenturi, id);
int count = Getcontentresolver (). Delete (URI, NULL, NULL);
result = Count = = 1;
} else {
Cursor Cursor2 = MediaStore.Images.Media.query (resolver, MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
New string[]{mediastore.images.media._id}, MediaStore.Images.Media.DATA + "=?",
New String[]{imgpath}, NULL);
if (Cursor2.movetofirst ()) {
Long id = cursor2.getlong (0);
Uri Contenturi = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
URI = Contenturis.withappendedid (Contenturi, id);
int count = Getcontentresolver (). Delete (URI, NULL, NULL);
result = Count = = 1;
}
}
Update to Gallery
Intent Intent = new Intent (intent.action_media_scanner_scan_file);
Intent.setdata (Uri.fromfile (New File (Imgpath)));
Sendbroadcast (Intent);
}
Toast Tool Class
Import Android.os.Handler;
Import Android.os.Looper;
Import android.view.Gravity;
Import Android.widget.TextView;
Import Android.widget.Toast;
/**
* <pre>
* Toast Related Tool class
* </pre>
*/
public class Toastutils {
Private Toastutils () {
throw new Unsupportedoperationexception ("u can ' t instantiate me ...");
}
private static Toast Stoast;
private static Handler Shandler = new Handler (Looper.getmainlooper ());
private static Boolean Isjumpwhenmore;
/**
* Toast Initialization
*
* @param Isjumpwhenmore When the toast is popped, is it to pop up the new toast or just change the text content
* <p>{@code true}: Pop up new toast <br>{@code false}: Only modify text content </p>
* <p> if {@code false} can be used to show any length of the toast </p>
*/
public static void Init (Boolean isjumpwhenmore) {
Toastutils.isjumpwhenmore = Isjumpwhenmore;
}
/**
* Safe to display short-time toast
*
* @param text
*/
public static void Showshorttoastsafe (final charsequence text) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (text, toast.length_short);
}
});
}
/**
* Safe to display short-time toast
*
* @param resId Resource ID
*/
public static void Showshorttoastsafe (final int resId) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (ResId, Toast.length_short);
}
});
}
/**
* Safe to display short-time toast
*
* @param resId Resource ID
* @param args parameter
*/
public static void Showshorttoastsafe (final int resId, final Object ... args) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (ResId, Toast.length_short, args);
}
});
}
/**
* Safe to display short-time toast
*
* @param format
* @param args parameter
*/
public static void Showshorttoastsafe (final String format, final Object ... args) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (format, toast.length_short, args);
}
});
}
/**
* Safe to display long-time toast
*
* @param text
*/
public static void Showlongtoastsafe (final charsequence text) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (text, Toast.length_long);
}
});
}
/**
* Safe to display long-time toast
*
* @param resId Resource ID
*/
public static void Showlongtoastsafe (final int resId) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (ResId, Toast.length_long);
}
});
}
/**
* Safe to display long-time toast
*
* @param resId Resource ID
* @param args parameter
*/
public static void Showlongtoastsafe (final int resId, final Object ... args) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (ResId, Toast.length_long, args);
}
});
}
/**
* Safe to display long-time toast
*
* @param format
* @param args parameter
*/
public static void Showlongtoastsafe (final String format, final Object ... args) {
Shandler.post (New Runnable () {
@Override
public void Run () {
Showtoast (format, Toast.length_long, args);
}
});
}
/**
* Show short time toast
*
* @param text
*/
public static void Showshorttoast (Charsequence text) {
Showtoast (text, toast.length_short);
}
/**
* Show short time toast
*
* @param resId Resource ID
*/
public static void Showshorttoast (int resId) {
Showtoast (ResId, Toast.length_short);
}
/**
* Show short time toast
*
* @param resId Resource ID
* @param args parameter
*/
public static void Showshorttoast (int resId, Object ... args) {
Showtoast (ResId, Toast.length_short, args);
}
/**
* Show short time toast
*
* @param format
* @param args parameter
*/
public static void Showshorttoast (String format, Object ... args) {
Showtoast (format, toast.length_short, args);
}
/**
* Show long-time toast
*
* @param text
*/
public static void Showlongtoast (Charsequence text) {
Showtoast (text, Toast.length_long);
}
/**
* Show long-time toast
*
* @param resId Resource ID
*/
public static void Showlongtoast (int resId) {
Showtoast (ResId, Toast.length_long);
}
/**
* Show long-time toast
*
* @param resId Resource ID
* @param args parameter
*/
public static void Showlongtoast (int resId, Object ... args) {
Showtoast (ResId, Toast.length_long, args);
}
/**
* Show long-time toast
*
* @param format
* @param args parameter
*/
public static void Showlongtoast (String format, Object ... args) {
Showtoast (format, Toast.length_long, args);
}
/**
* Show Toast
*
* @param text
* @param duration Display length
*/
private static void Showtoast (charsequence text, int duration) {
if (Isjumpwhenmore) canceltoast ();
if (stoast = = null) {
Stoast = Toast.maketext (Utils.getcontext (), text, duration);
TextView TV = (TextView) Stoast.getview (). Findviewbyid (Android. R.id.message);
Tv.settextsize (17);
Stoast.setgravity (gravity.center,0,0);
} else {
Stoast.settext (text);
Stoast.setduration (duration);
}
Stoast.show ();
}
/**
* Show Toast
*
* @param resId Resource ID
* @param duration Display length
*/
private static void Showtoast (int resId, int duration) {
Showtoast (Utils.getcontext (). Getresources (). GetText (ResId). toString (), duration);
}
/**
* Show Toast
*
* @param resId Resource ID
* @param duration Display length
* @param args parameter
*/
private static void Showtoast (int resId, int duration, Object ... args) {
Showtoast (String.Format (utils.getstring (resId), args), duration);
}
/**
* Show Toast
*
* @param format
* @param duration Display length
* @param args parameter
*/
private static void Showtoast (String format, int duration, Object ... args) {
Showtoast (String.Format (format, args), duration);
}
/**
* Cancel the toast display
*/
public static void Canceltoast () {
if (stoast! = null) {
Stoast.cancel ();
Stoast = null;
}
}
}
Android Delete album pictures and sync to Gallery