zoukankan      html  css  js  c++  java
  • 发送广播重新挂载SD卡,使图库可以及时显示自己保存的图片(无需手机重启)

    我们或许经常会遇到这种情况,明明保存了图片,但是当你打开图片时,却没有找到这张图片,手机重启之后才能看到。这是因为SD卡并没有重新挂载,图库也无法把这张图片加载进去,解决这个问题非常简单,只需要我们模拟一个广播,使SD卡重新挂载即可!方法如下:

    /**
    	 * 发送广播,重新挂载SD卡
    	 */
    	private void sendBroadCaseRemountSDcard() {
    		Intent intent = new Intent();
    		// 重新挂载的动作
    		intent.setAction(Intent.ACTION_MEDIA_MOUNTED);
    		// 要重新挂载的路径
    		intent.setData(Uri.fromFile(Environment.getExternalStorageDirectory()));
    		sendBroadcast(intent);
    	}

  • 相关阅读:
    ant design pro梳理
    JSON.stringify()
    数组小细节
    js this细节
    策略模式解决if-else过多
    使用useState的赋值函数异步更新问题
    Hook
    React Api
    Intent
    树的非递归遍历
  • 原文地址:https://www.cnblogs.com/loonggg/p/4981811.html
Copyright © 2011-2022 走看看