日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

android 拍照不能保存图片格式,Android 拍照后保存到手机里,在相册找不到

發布時間:2025/3/21 Android 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 拍照后保存到手机里,在相册找不到的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。