2012-03-10 49 views
0

我有圖像的網址。 我正在創建它的.JPEG文件並保存在SD卡的目錄中。下載圖像並在android的活動中顯示

下載所有圖像(創建位圖並以JPEG壓縮)後,我打電話給另一個意圖,該意圖應顯示下載到該目錄中的所有圖像。

但我看到空白。

我挑逗了DDMS,發現正確大小的jpeg已經下載到我所需的目錄中。但我的意圖沒有顯示。

令我驚訝的是,當我關閉模擬器,重新啓動它,重新運行程序與另一組圖像鏈接,現在我的意圖是顯示以前下載的圖像! (而不是在本次程序中下載的圖像)。

以下是我用於顯示下載圖像的代碼: 任何人都可以幫助我嗎?

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.imagechooser); 


     Bundle bundle = this.getIntent().getExtras(); 
     thumbNailsLnkdhs = (LinkedHashSet<String>) bundle.getSerializable("keyThumbNails"); 

     Toast.makeText(getApplicationContext(), 
       "ThumbNailsLnkdhs size in new intent: "+thumbNailsLnkdhs.size(), Toast.LENGTH_LONG).show(); 

     final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID }; 
     final String orderBy = MediaStore.Images.Media._ID; 


     Cursor imagecursor=managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, 
       columns, 
        MediaStore.Images.Media.DATA + " like ? ", 
        new String[] {"%myDesiredDirectory%"}, 
        null); 

     Log.d(LOGGER, "cursor made"); 
     int colcount=imagecursor.getColumnCount(); 
     //.d(LOGGER, "cursor column count is: "+colcount); 

     int count =imagecursor.getCount(); 
     //Log.d(LOGGER, "count is: "+count); 

     String colnAME=imagecursor.getColumnName(0); 
     //Log.d(LOGGER, "COL NAME FOR 0TH COLUMN="+colnAME); 
     String colnAME_1=imagecursor.getColumnName(1); 
     //Log.d(LOGGER, "COL NAME FOR 1st COLUMN="+colnAME_1); 


     int image_column_index = imagecursor.getColumnIndex(imagecursor.getColumnName(1)); 
     //Log.d(LOGGER, "image_column_index="+image_column_index); 

     //Log.d(LOGGER, "ThumbNailsLnkdhs size: "+ThumbNailsLnkdhs.size()); 

     //int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID); 


     this.count = imagecursor.getCount(); 
     //Log.d(LOGGER, "this.count="+this.count); 

     this.thumbnails = new Bitmap[this.count]; 
     this.arrPath = new String[this.count]; 
     this.thumbnailsselection = new boolean[this.count]; 

     for (int i = 0; i < this.count; i++) { 
      imagecursor.moveToPosition(i); 
      int id = imagecursor.getInt(image_column_index); 
      int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA); 
      //Log.d(LOGGER, "dataColumnIndex="+dataColumnIndex); 

      thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
        getApplicationContext().getContentResolver(), id, 
        MediaStore.Images.Thumbnails.MICRO_KIND, null); 

      arrPath[i]= imagecursor.getString(dataColumnIndex); 
     } 
     GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid); 
     imageAdapter = new ImageAdapter(); 
     imagegrid.setAdapter(imageAdapter); 
     imagecursor.close(); 
    } 

好了,按以下ansr建議, 我發現我需要後,我創建其物理文件中插入圖像畫廊。

我試圖

MediaStore.Images.Media.insertImage(getContentResolver(), bitmapimage, 
imgname+ ".jpg Card Image", "imgDescription" 
+ ".jpg Card Image"); 

,但不可能在一類的下載,創建物理文件,而不是旅館的活動使用getcontentresolver作爲即時通訊。

所以,我想

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" 
       +Environment.getExternalStorageDirectory() 
     + "/myDesiredDirectory/"))) 
在我的活動,顯示先前下載的圖像

...但它沒有幫助我,以顯示新下載的圖片... 所以試圖

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" 

       + Environment.getExternalStorageDirectory()+))); 

    this also not showing new images :(

任何人都可以幫助我呢?

回答

0

當您通過DDMS手動將圖像放入AVD時,您需要從設置中正確掃描介質?

同樣的問題在這裏

下載後,您需要通過編碼掃描媒體和集適配器之前關閉圖像用光標。

+0

謝謝!任何想法如何只掃描特定目錄? – adityag 2012-03-10 10:25:53

+0

現在我正在尋找一種方法來掃描我的活動中的特定方向。 – adityag 2012-03-10 12:21:29

0

您正在創建一個新的ImageAdapter,然後將GridView附加到該「新」適配器。換句話說,你的GridView必須是空的,因爲它被連接到一個新的空白適配器。

你在哪裏連接位圖/光標到適配器/視圖?

相關問題