zoukankan      html  css  js  c++  java
  • android 刷新系统资源库

    通过自己发送广播,mediascanner接收到广播会启动扫描资源库的服务,从而刷新资源库


    -扫描全部


    1. public void systemScan(){  
    2.         sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://"  
    3.                 + Environment.getExternalStorageDirectory())));  
    4.     }  

    -  扫描某个文件  参数:填入该文件的路径


    1. public void fileScan(String file){  
    2.         Uri data = Uri.parse("file://"+file);  
    3.           
    4.         sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));  
    5.     }  

    - 扫描文件夹 参数:填入该文件夹路径


    1. public void fileScan(String file){  
    2.         Uri data = Uri.parse("file://"+file);  
    3.           
    4.         sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));  
    5.     }  
    6.       
    7.     public void folderScan(String path){  
    8.         File file = new File(path);  
    9.           
    10.         if(file.isDirectory()){  
    11.             File[] array = file.listFiles();  
    12.               
    13.             for(int i=0;i<array.length;i++){  
    14.                 File f = array[i];  
    15.                   
    16.                 if(f.isFile()){//FILE TYPE  
    17.                     String name = f.getName();  
    18.                       
    19.                     if(name.contains(".mp3")){  
    20.                         fileScan(f.getAbsolutePath());  
    21.                     }  
    22.                 }  
    23.                 else {//FOLDER TYPE  
    24.                     folderScan(f.getAbsolutePath());  
    25.                 }  
    26.             }  
    27.         }  
    28.     }








  • 相关阅读:
    在controller间分享数据(第一种办法)
    AngularJS之Factory vs Service vs Provider
    directive和controller如何通信
    AngularJS 之Services讲解
    AngularJS心得体会
    int 和Integer
    2019天梯赛练习题(L2专项练习)
    2019天梯赛练习题(L1专项练习)
    Hash冲突的几种解决方法
    HashMap
  • 原文地址:https://www.cnblogs.com/liulaolaiu/p/11744694.html
Copyright © 2011-2022 走看看