zoukankan      html  css  js  c++  java
  • 主动通知Android系统图库进行更新

    项目中遇到调用图库进行图片的选择,因为不能主动及时更新,遂实现代码调用实现主动及时更新。

    废话不多刷,看代码。

    方式一,发送一个广播,

    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse("file://"+fileSD_file)));

    方式二,通过MediaScannerConnection 类

    MediaScannerConnection.scanFile(context, new String[]{fileSD_file.toString()}, null, null);

    方式三,也是通过MediaScannerConnection 类

    MediaScannerConnection msc=new MediaScannerConnection(context,new MediaScannerConnectionClient(){
    @Override
    public void onMediaScannerConnected() {
    // TODO Auto-generated method stub

    }
    @Override
    public void onScanCompleted(String path, Uri uri) {
    // TODO Auto-generated method stub

    }
    }); 
    msc.connect();
    try {
    Thread.sleep(1000);
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    URL url = null;
    try {
    url = fileSD_file.toURL();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    }

    MimeTypeMap mtm=MimeTypeMap.getSingleton();

    msc.scanFile(fileSD_file.toString(), mtm.getMimeTypeFromExtension(mtm.getFileExtensionFromUrl(url.toString())));

    //此句上面的一句可以,下面的一句也可以,都适合这种方法(已用颜色标示)。

    // msc.scanFile(fileSD_file.getAbsolutePath(), null);

    msc.disconnect();

    来源:http://www.bozhiyue.com/anroid/boke/2016/0318/3524.html

  • 相关阅读:
    mysql 快速生成百万条测试数据
    DEV SIT UAT
    云计算的三层SPI模型
    go的下载
    redis主从 哨兵
    Mybatis 插入操作时获取主键 (Oracle 触发器与SEQ)
    oracle创建表空间
    mycat源码分析
    js判断是否是数字通用写法
    spring aop获取目标对象的方法对象(包括方法上的注解)
  • 原文地址:https://www.cnblogs.com/ruiati/p/4061979.html
Copyright © 2011-2022 走看看