2014-05-21 10 views
7

Ho sfogliato l'immagine dalla galleria e l'ho impostata su ImageView ora ho bisogno di ottenere il nome dell'immagine dell'immagine che è stata impostata in ImageView. Ho allegato il mio codice qui sotto.ottenendo il nome dell'immagine dell'immagine selezionata dalla galleria in Android

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Log.d("req","req"+requestCode); 
    Log.d("res","res"+resultCode); 

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { 
     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(); 
     imageView = (ImageView) findViewById(R.id.imgView); 

     imageView1 = (ImageView) findViewById(R.id.imgView1); 

     if(browse == 1){ 
      imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
     } 
     if(browse == 2){ 
      imageView1.setImageBitmap(BitmapFactory.decodeFile(picturePath)); 
     } 
     String resName = getResources().getResourceEntryName(R.id.imgView); 
     Toast.makeText(getApplicationContext(), "BBB"+resName,Toast.LENGTH_LONG).show(); 

    } 

risposta

11

Prova questa how to get file name from URI

File f = new File(picturePath); 
String imageName = f.getName(); 
+0

thank u ottenere il nome del file ... come confrontare due file..but percorso immagine è stessa – user3415586

+0

uso questa funzione f.compareTo (file2); – Shini

+0

camparing f1.compareTo (f2); sto ottenendo il valore 0 – user3415586

Problemi correlati