Java Code Examples for android.content.Intent.ACTION_MEDIA_SCANNER_SCAN_FILE

The following are Jave code examples for showing how to use ACTION_MEDIA_SCANNER_SCAN_FILE of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Lunary-Ethereum-Wallet   File: WalletStorage.java   View Source Code Vote up 7 votes
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 2
Project: simple-share-android   File: FileUtils.java   View Source Code Vote up 7 votes
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 3
Project: ScreenRecordCaptureMaster   File: RecordScreenDialog.java   View Source Code Vote up 7 votes
/**
 * 检查保存的文件并且更新到相册
 */
private void checkFile() {
    if (mFile.exists()) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            mediaScanIntent.setData(Uri.fromFile(mFile));
            getContext().sendBroadcast(mediaScanIntent);
        } else {
            getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse(mFile.getPath())));
        }
    }
}
 
Example 4
Project: aos-MediaLib   File: VideoStore.java   View Source Code Vote up 6 votes
/**
 * set hidden false when reindex is true
 * */

public static void requestIndexing(Uri uri, Context context, boolean reIndex) {
    if (uri == null || context == null) {
        Log.w(TAG, "requestIndexing: file or context null");
        return;
    }
    //first check if video is hidden
    if(reIndex) {
        Uri tmp = uri;
        if ("file".equals(tmp.getScheme())) {
            tmp = Uri.parse(uri.toString().substring("file://".length()));
        }
        String whereR = VideoStore.MediaColumns.DATA + " = ?";
        final ContentValues cvR = new ContentValues(1);
        String col = VideoStore.Video.VideoColumns.ARCHOS_HIDDEN_BY_USER;
        cvR.put(col, 0);
        context.getContentResolver().update(VideoStore.Video.Media.EXTERNAL_CONTENT_URI, cvR, whereR, new String[]{tmp.toString()});
    }
    String action;
    if ((!Utils.isLocal(uri)||UriUtils.isContentUri(uri))&& UriUtils.isIndexable(uri)) {
        action = ArchosMediaIntent.ACTION_VIDEO_SCANNER_SCAN_FILE;
    }
    else {
        action = Intent.ACTION_MEDIA_SCANNER_SCAN_FILE;
        if(uri.getScheme()==null)
            uri = Uri.parse("file://"+uri.toString());
    }
    Intent scanIntent = new Intent(action);
    scanIntent.setData(uri);
    if(!UriUtils.isContentUri(uri)) // doesn't work with content
        context.sendBroadcast(scanIntent);
    else
        NetworkScannerServiceVideo.startIfHandles(context, scanIntent);
}
 
Example 5
Project: Lunary-Ethereum-Wallet   File: WalletStorage.java   View Source Code Vote up 6 votes
private boolean exportWallet(Activity c, boolean already) {
    if (walletToExport == null) return false;
    if (walletToExport.startsWith("0x"))
        walletToExport = walletToExport.substring(2);

    if (ExternalStorageHandler.hasPermission(c)) {
        File folder = new File(Environment.getExternalStorageDirectory(), "Lunary");
        if (!folder.exists()) folder.mkdirs();

        File storeFile = new File(folder, walletToExport + ".json");
        try {
            copyFile(new File(c.getFilesDir(), walletToExport), storeFile);
        } catch (IOException e) {
            return false;
        }

        // fix, otherwise won't show up via USB
        Intent mediaScannerIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri fileContentUri = Uri.fromFile(storeFile); // With 'permFile' being the File object
        mediaScannerIntent.setData(fileContentUri);
        c.sendBroadcast(mediaScannerIntent); // With 'this' being the context, e.g. the activity
        return true;
    } else if (!already) {
        ExternalStorageHandler.askForPermission(c);
        return exportWallet(c, true);
    } else {
        return false;
    }
}
 
Example 6
Project: androidadvanced   File: MainActivity.java   View Source Code Vote up 6 votes
private void addPicToGallery() {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(photoPath);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    this.sendBroadcast(mediaScanIntent);
}
 
Example 7
Project: Hotspot-master-devp   File: BitmapCommonUtils.java   View Source Code Vote up 6 votes
/**
 * 通知系统相册更新
 * @param context
 * @param filePath
 */
public static void notifyGallery(Context context,String filePath) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri uri = Uri.fromFile(new File(filePath));
    intent.setData(uri);
    context.sendBroadcast(intent);
}
 
Example 8
Project: yyox   File: PictureUtil.java   View Source Code Vote up 6 votes
/**
 * 添加到图库
 */
public static void galleryAddPic(Context context, String path) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    File f = new File(path);
    Uri contentUri = Uri.fromFile(f);
    mediaScanIntent.setData(contentUri);
    context.sendBroadcast(mediaScanIntent);
}
 
Example 9
Project: TrackPlan-app   File: addstudpicActivity.java   View Source Code Vote up 6 votes
private void galleryAddPic() {
    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);
}
 
Example 10
Project: PlusGram   File: AndroidUtilities.java   View Source Code Vote up 6 votes
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("tmessages", e);
    }
}
 
Example 11
Project: Hitalk   File: ImageCaptureManager.java   View Source Code Vote up 6 votes
public void galleryAddPic() {
  Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

  if (TextUtils.isEmpty(mCurrentPhotoPath)) {
    return;
  }

  File f = new File(mCurrentPhotoPath);
  Uri contentUri = Uri.fromFile(f);
  mediaScanIntent.setData(contentUri);
  mContext.sendBroadcast(mediaScanIntent);
}
 
Example 12
Project: COB   File: CameraLauncher.java   View Source Code Vote up 5 votes
private void refreshGallery(Uri contentUri) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    this.cordova.getActivity().sendBroadcast(mediaScanIntent);
}
 
Example 13
Project: alerta-fraude   File: LocalFilesystem.java   View Source Code Vote up 5 votes
/**
 * 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 14
Project: Bigbang   File: DonateActivity.java   View Source Code Vote up 5 votes
private void sendBrodcast4Update(File file) {
    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    Uri uri = Uri.fromFile(file);
    intent.setData(uri);
    sendBroadcast(intent);
}
 
Example 15
Project: localcloud_fe   File: CameraLauncher.java   View Source Code Vote up 5 votes
private void refreshGallery(Uri contentUri) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    this.cordova.getActivity().sendBroadcast(mediaScanIntent);
}
 
Example 16
Project: microbit   File: AudioRecorderActivity.java   View Source Code Vote up 5 votes
private void refreshAudio(File file) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(Uri.fromFile(file));
    sendBroadcast(mediaScanIntent);
}
 
Example 17
Project: siiMobilityAppKit   File: CameraLauncher.java   View Source Code Vote up 5 votes
private void refreshGallery(Uri contentUri) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(contentUri);
    this.cordova.getActivity().sendBroadcast(mediaScanIntent);
}
 
Example 18
Project: keemob   File: LocalFilesystem.java   View Source Code Vote up 5 votes
/**
 * 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 19
Project: PairingExample   File: MainActivity.java   View Source Code Vote up 5 votes
private void launchMediaScanIntent()
{
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(imageUri);
    this.sendBroadcast(mediaScanIntent);
}
 
Example 20
Project: microbit   File: CameraActivity_OldAPI.java   View Source Code Vote up 5 votes
private void refreshGallery(File file) {
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    mediaScanIntent.setData(Uri.fromFile(file));
    sendBroadcast(mediaScanIntent);
}