2016-04-14 50 views
0

我想在android自定義相機中打開畫廊。但是,重新啓動手機時顯示並保存SD卡。我的代碼中有什麼問題?Android相機不顯示打開畫廊只有在重新啓動手機時纔有效

Uri selectedImage = data.getData(); 
    String[] filePathColumn = {MediaStore.Images.Media.DATA}; 
    Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
    cursor.moveToFirst(); 
    int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
    String picturePath = cursor.getString(columnIndex); 
    cursor.close(); 

回答

0

我不明白這個問題,你問你爲什麼Open Gallery Button只顯示你重啓手機,或者爲什麼只有重啓後才顯示照片?

如果是後者,請嘗試調用媒體掃描程序。在吐司之前或之後。

public void addPictureToGallery(String fileName) { 
    File f = new File(fileName); 
    Uri contentUri = Uri.fromFile(f); 
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri); 
    sendBroadcast(mediaScanIntent); 
} 
+0

我在問爲什麼打開圖庫按鈕只顯示重新啓動手機。我那樣試過。 if(id == R.id.open_gallery){0} {0} {0} {{0}}意圖mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse(「content:// media/internal/images/media」)); sendBroadcast(mediaScanIntent);不顯示任何東西 – xiac

+0

只有當您重新啓動手機時,相機應用程序上的按鈕纔會顯示出來?你是否在任何地方隱藏了按鈕?如果您重新啓動應用程序,該按鈕會顯示嗎? – user732029

+0

我使用的菜單,當我按下我的應用程序上的照片菜單,它保存sdcart,然後當我按下我的應用程序打開畫廊菜單不顯示圖片。重新啓動手機後,它顯示圖像 – xiac