SORU
30 Ocak 2010, CUMARTESİ


/Android's inşa Galeri uygulaması programlı bir resim seç al

Benim uygulama içinde Galeri-dahili app resim / resmi açmak için çalışıyorum.

Resmi bir URI (resim SD kart üzerinde yer almaktadır.

Herhangi bir öneriniz var mı?

CEVAP
14 NİSAN 2010, ÇARŞAMBA


Bu tam bir çözümdür. Sadece bilgi @deli tarafından cevap aşağıda verilen bu kod örneği güncelledik. Ayrıca kontrol çözümü aşağıda @Khobaib picasa görüntüleri ile başa çıkmak için nasıl açıklayan.

Güncelleme

Sadece orijinal cevabımı Gözden geçirdim ve github kontrol edebilir ve doğrudan sisteminize aktarabilirsiniz basit Android Studio bir proje oluşturdu.

https://github.com/hanscappelle/SO-2169649

(birden fazla dosya seçimi hala çalışması gerektiğini unutmayın)

Tek Resim Seçimi

Dosyadan görüntü desteği ile kaşifler kullanıcı mad için teşekkürler.

public class BrowsePictureActivity extends Activity {

    // this is the action code we use in our intent, 
    // this way we know we're looking at the response from our own action
    private static final int SELECT_PICTURE = 1;

    private String selectedImagePath;

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

        findViewById(R.id.Button01)
                .setOnClickListener(new OnClickListener() {

                    public void onClick(View arg0) {

                        // in onCreate or any event where your want the user to
                        // select a file
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction(Intent.ACTION_GET_CONTENT);
                        startActivityForResult(Intent.createChooser(intent,
                                "Select Picture"), SELECT_PICTURE);
                    }
                });
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                Uri selectedImageUri = data.getData();
                selectedImagePath = getPath(selectedImageUri);
            }
        }
    }

    /**
     * helper to retrieve the path of an image URI
     */
    public String getPath(Uri uri) {
            // just some safety built in 
            if( uri == null ) {
                // TODO perform some logging or show user feedback
                return null;
            }
            // try to retrieve the image from the media store first
            // this will only work for images selected from gallery
            String[] projection = { MediaStore.Images.Media.DATA };
            Cursor cursor = managedQuery(uri, projection, null, null, null);
            if( cursor != null ){
                int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            }
            // this is our fallback here
            return uri.getPath();
    }

}

Birden Fazla Resim Seçmek

Beri birisi bir açıklama istenen bilgileri ve daha fazla bilgi topladık.

Niyet 4 ** fazladan bir parametre ayarlayın:

intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);

Ve Sonuç işleme parametre için kontrol edin:

if (Intent.ACTION_SEND_MULTIPLE.equals(data.getAction()))
        && Intent.hasExtra(Intent.EXTRA_STREAM)) {
    // retrieve a collection of selected images
    ArrayList<Parcelable> list = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    // iterate over these images
    if( list != null ) {
       for (Parcelable parcel : list) {
         Uri uri = (Uri) parcel;
         // TODO handle the images one by one here
       }
   }
} 

Bu API seviyesi 18 tarafından desteklenen unutmayın .

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • andyabc45

    andyabc45

    1 Mayıs 2011
  • Dylan Brenan

    Dylan Brenan

    22 Aralık 2009
  • Grace Su

    Grace Su

    6 Ocak 2006