android 拍照不能保存图片格式,Android 拍照后保存到手机里,在相册找不到
1、拍完照后用下面的方法寫到相冊中
MediaStore.Images.Media.insertImage(AddCommercial.this.getContentResolver(),
file.getAbsolutePath(), name, null);
2、通知系統跟新手機儲存目錄
掃描拍照后的指定文件(推薦)
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri uri = Uri.fromFile(new File(fileName));
System.out.println(fileName+"uriuri:::"+uri);
intent.setData(uri);
sendBroadcast(intent);
掃描整個sd卡(掃描費時間)
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + Environment.getExternalStorageDirectory())));
FileOutputStream b = null;
Bitmap bitmap = null; ?? ??? ??? ?String wenjian = "文件名" ; ?? ??? ??? ?try { ? ?? ??? ??? ??? ?String sdStatus = Environment.getExternalStorageState(); ? ?? ??? ??? ??? ?if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 檢測sd是否可用 ? ?? ??? ??? ??? ??? ?MyToast.MyShow(AddCommercial.this, "請確認已經插入SD卡"); ?? ??? ??? ??? ??? ?return; ? ?? ??? ??? ??? ?} ? ?? ??? ??? ??? ?Bundle bundle = data.getExtras(); ? ?? ??? ??? ??? ?bitmap = (Bitmap) bundle.get("data");// 獲取相機返回的數據,并轉換為Bitmap圖片格式 ? ?? ??? ??? ??? ?File appDir = new File(Environment.getExternalStorageDirectory(), wenjian); ?? ??? ??? ???? if (!appDir.exists()) { ?? ??? ??? ???????? appDir.mkdir(); ?? ??? ??? ???? } ?? ??? ??? ???? String name = System.currentTimeMillis() + ".jpg"; ?? ??? ??? ???? File file = new File(appDir, name); ?? ??? ??? ??? ?fileName = Environment.getExternalStorageDirectory()+"/"+wenjian+"/"+name; ?? ??? ??? ??? ?cameralist.add(fileName); ?? ??? ??? ??? ?b = new FileOutputStream(file); ? ?? ??? ??? ??? ?bitmap.compress(Bitmap.CompressFormat.JPEG, 100, b);// 把數據寫入文件 ? ?? ??? ??? ??? ?MediaStore.Images.Media.insertImage(AddCommercial.this.getContentResolver(), ?? ??? ??? ??? ??? ??? ??? ??? ?file.getAbsolutePath(), name, null); ?? ??? ??? ??? ?Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);? ? ?? ??? ??? ??? ?Uri uri = Uri.fromFile(new File(fileName)); ?? ??? ??? ??? ?System.out.println(fileName+"uriuri:::"+uri); ?? ??? ??? ??? ?intent.setData(uri);? ? ?? ??? ??? ??? ?sendBroadcast(intent); ?? ??? ??? ?} catch (Exception e) { ? ?? ??? ??? ??? ?e.printStackTrace(); ? ?? ??? ??? ?} finally { ? ?? ??? ??? ??? ?try { ? ?? ??? ??? ??? ??? ?b.flush(); ? ?? ??? ??? ??? ??? ?b.close(); ? ?? ??? ??? ??? ?} catch (Exception e) { ? ?? ??? ??? ??? ??? ?e.printStackTrace(); ? ?? ??? ??? ??? ?} ? ?? ??? ??? ?}
總結
以上是生活随笔為你收集整理的android 拍照不能保存图片格式,Android 拍照后保存到手机里,在相册找不到的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android ip地址扫描,Andro
- 下一篇: android service使用han