标签:android style blog io ar color sp 文件 on
启动MediaScanner服务,扫描媒体文件,程序通过发送下面的Intent启动MediaScanner服务。
public void scanFile(Context ctx, String filePath) { Intent scanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); scanIntent.setData(Uri.fromFile(new File(filePath))); ctx.sendBroadcast(scanIntent); }
public static final String ACTION_MEDIA_SCANNER_SCAN_DIR = "android.intent.action.MEDIA_SCANNER_SCAN_DIR"; public void scanDirAsync(Context ctx, String dir) { Intent scanIntent = new Intent(ACTION_MEDIA_SCANNER_SCAN_DIR); scanIntent.setData(Uri.fromFile(new File(dir))); ctx.sendBroadcast(scanIntent); }
public void sdScan(){ sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); }
标签:android style blog io ar color sp 文件 on
原文地址:http://www.cnblogs.com/yydcdut/p/4114383.html