Example usage for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE

List of usage examples for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE

Introduction

In this page you can find the example usage for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE.

Prototype

String ACTION_MEDIA_SCANNER_SCAN_FILE

To view the source code for android.content Intent ACTION_MEDIA_SCANNER_SCAN_FILE.

Click Source Link

Document

Broadcast Action: Request the media scanner to scan a file and add it to the media database.

Usage

From source file:Main.java

/**
 * copy current image to Gallery//w ww  . java 2s.  c  o m
 */
public static void galleryAddPic(Uri currentImageUri, Activity activity) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(currentImageUri);
    activity.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static void addNewImageToGallery(Context context, String filePath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(filePath);
    Uri contentUri = Uri.fromFile(f);/*from w  ww .  j av  a 2  s.  c  o m*/
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

public static void scanMediaFileToGallery(Context context, String path) {
    File file = new File(path);
    Uri uri = Uri.fromFile(file);/*from w  ww .  ja v  a2  s.  co  m*/
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
    context.sendBroadcast(intent);
}

From source file:Main.java

public static void sendIntent(Context context, Uri uri) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(uri);/* w w  w  .  ja v  a 2s  .  com*/
    context.sendBroadcast(intent);
}

From source file:Main.java

/**
 * Add file photo to gallery after capture from camera or downloaded.
 *
 * @param context/*  w  w  w  .ja  v a2s . co  m*/
 * @param file
 */
public static void galleryAddPic(Context context, File file) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri contentUri = Uri.fromFile(file);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}

From source file:Main.java

/**
 * Forces the Android gallery to  refresh its thumbnail images.
 * @param context/*  w w w  .  j a  va2  s. co m*/
 * @param fdelete
 */
private static void refreshGalleryImages(Context context, File fdelete) {
    try {
        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                Uri.parse("file://" + Environment.getExternalStorageDirectory())));
    } catch (Exception e1) {
        try {
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri contentUri = Uri.fromFile(fdelete);
            mediaScanIntent.setData(contentUri);
            context.sendBroadcast(mediaScanIntent);
        } catch (Exception e2) {
        }
    }
}

From source file:Main.java

public static void notifyFileSystemChanged(String path, Context mContext) {
    if (path == null)
        return;/*w w w  .ja v  a2 s .co m*/
    final File f = new File(path);
    final Intent intent;
    if (f.isDirectory()) {
        intent = new Intent(Intent.ACTION_MEDIA_MOUNTED);
        intent.setClassName("com.android.providers.media", "com.android.providers.media.MediaScannerReceiver");
        intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));

    } else {
        intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(new File(path)));

    }
    mContext.sendBroadcast(intent);
}

From source file:Main.java

public static void disImage(Activity act, File file) {
    Intent itt = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    itt.setData(Uri.fromFile(file));//from w  w  w  .  j  a  va 2s  . com
    act.sendBroadcast(itt);

    Intent it = new Intent(Intent.ACTION_VIEW);
    it.setDataAndType(Uri.parse(file.getPath()), "image/*");
    act.startActivity(it);
}

From source file:Main.java

public static void refreshContent(Context context, String path) {
    Uri data = Uri.parse("file://" + path);
    context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
}

From source file:Main.java

public static boolean insertMediaStore(Context context, File file, String imageName) {
    if (context == null || file == null || !file.exists()) {
        return false;
    }//from  w  w  w . ja  v  a2s  .c  om

    if (TextUtils.isEmpty(imageName)) {
        imageName = SystemClock.currentThreadTimeMillis() + PNG;
    }
    try {

        MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), imageName,
                null);
        // String imagePath =
        // MediaStore.Images.Media.insertImage(getContentResolver(),
        // bitmap, "", "");

        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;

}