android.content.Intent#ACTION_MEDIA_SCANNER_SCAN_FILE源码实例Demo

下面列出了android.content.Intent#ACTION_MEDIA_SCANNER_SCAN_FILE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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())));
    }
}
 
源代码2 项目: bcm-android   文件: WalletStorage.java
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

        }
    }
}
 
源代码3 项目: FireFiles   文件: FileUtils.java
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();
    }
}
 
源代码4 项目: Telegram   文件: AndroidUtilities.java
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);
    }
}
 
源代码5 项目: Telegram-FOSS   文件: AndroidUtilities.java
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);
    }
}
 
源代码6 项目: Yahala-Messenger   文件: Utilities.java
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);
}
 
源代码7 项目: SimpleExplorer   文件: MediaStoreUtils.java
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);
}
 
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);
    }
}
 
源代码9 项目: Android   文件: DownloadImage.java
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);
}
 
源代码10 项目: UltimateAndroid   文件: SignaturePadActivity.java
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;
}
 
源代码11 项目: cosu   文件: MainActivity.java
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);
}
 
源代码12 项目: Augendiagnose   文件: MediaStoreUtil.java
/**
 * 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);
}
 
源代码13 项目: BaseProject   文件: MediaUtil.java
/**
 * 通过广播的方式通知系统扫描某个文件
 * @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);
}
 
源代码14 项目: styT   文件: GankIoActivity.java
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);
}
 
源代码15 项目: reacteu-app   文件: LocalFilesystem.java
/**
 * 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);
}
 
源代码16 项目: android-palette   文件: MainActivity.java
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);
}
 
源代码17 项目: mytracks   文件: FileUtils.java
public static void updateMediaScanner(Context context, Uri uri) {
  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
  mediaScanIntent.setData(uri);
  context.sendBroadcast(mediaScanIntent);      
}
 
源代码18 项目: pixelvisualcorecamera   文件: FileSystem.java
/**
 * 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);
}
 
源代码19 项目: Camdroid   文件: StorageUtils.java
public static void updateMedia(Context ctx, File file) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file));
    ctx.sendBroadcast(intent);
}
 
源代码20 项目: RelaxFinger   文件: FloatingBallUtils.java
/**
 * 通知媒体库更新文件
 * @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);
}
 
 方法所在类
 同类方法