2017-07-26 8 views
1

写真を撮って外部ストレージ(「DCIM /カメラ」)に保存するAndroid-Appがあります。しかし、写真は私の便利な再起動後にのみ表示されます。 何らかのアップデートやこれを回避する方法はありますか?私の画像を保存するから画像はデバイスを再起動した後にのみ表示されます

私のソースコード:

var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim); 
var pictures = dir.AbsolutePath + "/Camera"; 
string name = System.DateTime.Now.ToString("yyyyMMdd_HHmmssfff") + ".jpg"; 
string filePath = System.IO.Path.Combine(pictures, name); 
FileStream output; 
Bitmap bitmap = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length); 
try 
{ 
    output = new FileStream(filePath, FileMode.Create); 
    bitmap.Compress(Bitmap.CompressFormat.Jpeg, 100, output); 
    output.Close(); 
    //Static Class that contains an methode for MediaScannerConnection.ScanFile 
    MediaGalleryHelper.AddFileToGallery(name); 
} 
catch (System.Exception ex) 
{ 
    System.Console.WriteLine(ex.ToString()); 
} 

答えて

1

あなたはフォトギャラリーに新しい写真が追加されたことを知らせなければなりません。

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

ここで「this」はアクティビティです。

+0

ありがとうございます!それはそれを本当にうまく解決しました。 – Julian

関連する問題