Java Code Examples for android.content.Intent#ACTION_MEDIA_SCANNER_SCAN_FILE

The following examples show how to use android.content.Intent#ACTION_MEDIA_SCANNER_SCAN_FILE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void onScanCompleted(String path, Uri uri) {
    Log.i("SingleMediaScanner", path);
    Log.i("SingleMediaScanner", uri.getPath());

    mMs.disconnect();

    MediaScannerConnection.scanFile(mContext, new String[] { mFile.getAbsolutePath() }, new String[] { "video/*" }, null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        mediaScanIntent.setData(Uri.fromFile(mFile));
        mContext.sendBroadcast(mediaScanIntent);
    }
    else
    {
        mContext.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(mFile.getAbsolutePath())));
    }
}
 
Example 2
public void importWallets(Context c, ArrayList<File> toImport) throws Exception {
    for (int i = 0; i < toImport.size(); i++) {

        String address = stripWalletName(toImport.get(i).getName());
        if (address.length() == 40) {
            copyFile(toImport.get(i), new File(c.getFilesDir(), address));
            if (!BuildConfig.DEBUG)
                toImport.get(i).delete();
            WalletStorage.getInstance(c).add(new FullWallet("0x" + address, address), c);
            AddressNameConverter.getInstance(c).put("0x" + address, "Wallet " + ("0x" + address).substring(0, 6), c);

            Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            Uri fileContentUri = Uri.fromFile(toImport.get(i)); // With 'permFile' being the File object
            mediaScannerIntent.setData(fileContentUri);
            c.sendBroadcast(mediaScannerIntent); // With 'this' being the context, e.g. the activity

        }
    }
}
 
Example 3
Source Project: FireFiles   File: FileUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static void updateMediaStore(Context context, ArrayList<DocumentInfo> docs, String parentPath) {
    try {
        if(Utils.hasKitKat()){
            ArrayList<String> paths = new ArrayList<>();
            for(DocumentInfo doc : docs){
                paths.add(parentPath + File.separator + doc.displayName);
            }
            String[] pathsArray = paths.toArray(new String[paths.size()]);
            FileUtils.updateMediaStore(context, pathsArray);
        }
        else{
            Uri contentUri = Uri.fromFile(new File(parentPath).getParentFile());
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, contentUri);
            context.sendBroadcast(mediaScanIntent);
        }
    }
    catch (Exception e){
        e.printStackTrace();
    }
}
 
Example 4
public static void addMediaToGallery(Uri uri) {
    if (uri == null) {
        return;
    }
    try {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        mediaScanIntent.setData(uri);
        ApplicationLoader.applicationContext.sendBroadcast(mediaScanIntent);
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 5
public static void addMediaToGallery(Uri uri) {
    if (uri == null) {
        return;
    }
    try {
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        mediaScanIntent.setData(uri);
        ApplicationLoader.applicationContext.sendBroadcast(mediaScanIntent);
    } catch (Exception e) {
        FileLog.e(e);
    }
}
 
Example 6
Source Project: Yahala-Messenger   File: Utilities.java    License: MIT License 5 votes vote down vote up
public static void addMediaToGallery(Uri uri) {
    if (uri == null) {
        return;
    }
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(uri);
    ApplicationLoader.applicationContext.sendBroadcast(mediaScanIntent);
}
 
Example 7
public static void addFileToMediaStore(final String path, Context context) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File file = new File(path);
    Uri contentUri = Uri.fromFile(file);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}
 
Example 8
private void addPictureToGallery(@NonNull Context context, @NonNull String photoPath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    try {
        File f = new File(photoPath);
        Uri contentUri = Uri.fromFile(f);
        mediaScanIntent.setData(contentUri);
        context.sendBroadcast(mediaScanIntent);
    } catch (NullPointerException e) {
        Log.e(TAG, "Error opening file: " + photoPath);
    }
}
 
Example 9
Source Project: Android   File: DownloadImage.java    License: MIT License 5 votes vote down vote up
private void galleryAddPic(String imagePath) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(imagePath);
    image_path = Uri.fromFile(f);
    mediaScanIntent.setData(image_path);
    mContext.sendBroadcast(mediaScanIntent);
}
 
Example 10
public boolean addSignatureToGallery(Bitmap signature) {
    boolean result = false;
    try {
        File photo = new File(getAlbumStorageDir("SignaturePad"), String.format("Signature_%d.jpg", System.currentTimeMillis()));
        saveBitmapToJPG(signature, photo);
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri contentUri = Uri.fromFile(photo);
        mediaScanIntent.setData(contentUri);
        sendBroadcast(mediaScanIntent);
        result = true;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}
 
Example 11
Source Project: cosu   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setImageToView(){
    //Save the file in gallery

    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(mCurrentPhotoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);

    // Get the dimensions of the view

    int targetH = imageView.getMaxHeight();
    int targetW = imageView.getMaxWidth();

    // Get the dimensions of the bitmap

    BitmapFactory.Options bmOptions = new BitmapFactory.Options();
    bmOptions.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    int photoH = bmOptions.outHeight;
    int photoW = bmOptions.outWidth;

    // Determine how much to scale down image
    int scaleFactor = Math.min(photoW/targetW, photoH/targetH);


    // Decode the image file into a Bitmap sized to fill the View
    bmOptions.inJustDecodeBounds = false;
    bmOptions.inSampleSize = scaleFactor;

    Bitmap imageBitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
    imageView.setImageBitmap(imageBitmap);

    // enable lock task button
    lockTaskButton.setEnabled(true);
}
 
Example 12
/**
 * Add a picture to the media store (via scanning).
 *
 * @param path the path of the image.
 */
public static void addPictureToMediaStore(@NonNull final String path) {
	Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
	File file = new File(path);
	Uri contentUri = Uri.fromFile(file);
	mediaScanIntent.setData(contentUri);
	Application.getAppContext().sendBroadcast(mediaScanIntent);
}
 
Example 13
Source Project: BaseProject   File: MediaUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 通过广播的方式通知系统扫描某个文件
 * @param appContext appContext
 * @param filePath 要被扫描的文件路径
 */
public static void notifySysScanFile(Context appContext, String filePath) {
    Uri data = Uri.parse("file://" + filePath);
    Intent toScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data);
    appContext.sendBroadcast(toScanIntent);
}
 
Example 14
Source Project: styT   File: GankIoActivity.java    License: Apache License 2.0 4 votes vote down vote up
private static void sendPictureStoredBroadcast(Context context, String qrSavePath) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri uri = Uri.fromFile(new File(qrSavePath));
    intent.setData(uri);
    context.sendBroadcast(intent);
}
 
Example 15
Source Project: reacteu-app   File: LocalFilesystem.java    License: MIT License 4 votes vote down vote up
/**
 * Send broadcast of new file so files appear over MTP
 */
private void broadcastNewFile(Uri nativeUri) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, nativeUri);
    context.sendBroadcast(intent);
}
 
Example 16
Source Project: android-palette   File: MainActivity.java    License: Apache License 2.0 4 votes vote down vote up
private static void scanFile(Context context, String filePath) {
    Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    scanIntent.setData(Uri.fromFile(new File(filePath)));
    context.sendBroadcast(scanIntent);
}
 
Example 17
Source Project: mytracks   File: FileUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void updateMediaScanner(Context context, Uri uri) {
  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
  mediaScanIntent.setData(uri);
  context.sendBroadcast(mediaScanIntent);      
}
 
Example 18
/**
 * Notifies system there is a new media file, so that it appears in photo galleries immediately.
 */
private static void updateMediaStore(Context context, File file) {
  Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
  intent.setData(Uri.fromFile(file));
  context.sendBroadcast(intent);
}
 
Example 19
Source Project: Camdroid   File: StorageUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void updateMedia(Context ctx, File file) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file));
    ctx.sendBroadcast(intent);
}
 
Example 20
/**
 * 通知媒体库更新文件
 * @param context
 * @param filePath 文件全路径
 *
 * */
public static void scanFile(Context context, String filePath) {
    Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    scanIntent.setData(Uri.fromFile(new File(filePath)));
    context.sendBroadcast(scanIntent);
}