生成图片后,保存到指定位置,或者直接保存到相册,但是保存后相册不能直接看到,这时就需要同时通知系统图库更新
//保存文件到指定路径    public void saveMyBitmap(Context context,Bitmap bitmap) {      String sdCardDir=Environment.getExternalStorageDirectory()+"/DCIM/";      File appDir =new File(sdCardDir, "HappyBirthday");      if (!appDir.exists()) {            appDir.mkdir();        }      String fileName = "HappyBirthday"+System.currentTimeMillis() + ".jpg";      File f = new File(appDir,fileName);      try {            FileOutputStream fos = new FileOutputStream(f);            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);            fos.flush();            fos.close();        } catch (FileNotFoundException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();    } 
 // 通知图库更新      Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);      Uri uri = Uri.fromFile(f);      intent.setData(uri);      context.sendBroadcast(intent);

当然方法不止这一种,但是在实际运行中,这个是最有效的。

更多相关文章

  1. android fih-mms的实现
  2. android 异常情况下的onSaveInatanceState()与onRestoreIntanceS
  3. Android(安卓)Jetpack 组件之 ViewModel(Kotlin)
  4. schema唤起指定页面
  5. android listview去除拉至顶部或底部时的蓝色
  6. android保存的wifi密码是明文……
  7. Android拍照获得图片URI为空的处理方法
  8. android 定义 程序 Scheme 接收特定URI开启Activity
  9. Win10下编译Android(安卓)Ogre3d 1.12.6

随机推荐

  1. NDK C++线程中如何调用JAVA API
  2. android 使用post方式上传文件
  3. android 中 LocalSocket的基本使用方法
  4. Android(安卓)导航类型
  5. Android经常使用开源组件汇总
  6. 【Android】判断某个AP是否在系统中存在(P
  7. android post请求接口demo
  8. Android(安卓)Audio代码分析23 - attachA
  9. Android文件保存和读取
  10. android的Android(安卓)中Intent和Pendin