2011-12-01 12 views
12

हे, मैं किसी भी कैमरा एप्लिकेशन के माध्यम से उपयोगकर्ता द्वारा प्राप्त अंतिम तस्वीर प्राप्त करना चाहता हूं। मुझे नहीं पता किउपयोगकर्ता द्वारा ली गई अंतिम तस्वीर

कोई भी मेरी मदद कर सकता है?

आगे मैं .. एक ईमेल या एमएमएस के अनुलग्नक के रूप उस छवि को भेजने के लिए

धन्यवाद

+0

मुझे पता है कि यह काफी नहीं है जो आप पूछ रहे हैं, लेकिन हो सकता है कि आप इसका क्या मतलब हो? आप कैमरे की गतिविधि शुरू कर सकते हैं और परिणामस्वरूप उपयोगकर्ता को वह तस्वीर मिल सकती है। यहां देखें http://stackoverflow.com/questions/2314958/using-the-camera-activity-in-android – Craigy

उत्तर

44
// Find the last picture 
String[] projection = new String[]{ 
    MediaStore.Images.ImageColumns._ID, 
    MediaStore.Images.ImageColumns.DATA, 
    MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, 
    MediaStore.Images.ImageColumns.DATE_TAKEN, 
    MediaStore.Images.ImageColumns.MIME_TYPE 
    }; 
final Cursor cursor = getContext().getContentResolver() 
     .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, 
       null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"); 

// Put it in the image view 
if (cursor.moveToFirst()) { 
    final ImageView imageView = (ImageView) findViewById(R.id.pictureView); 
    String imageLocation = cursor.getString(1); 
    File imageFile = new File(imageLocation); 
    if (imageFile.exists()) { // TODO: is there a better way to do this? 
     Bitmap bm = BitmapFactory.decodeFile(imageLocation); 
     imageView.setImageBitmap(bm);   
    } 
} 

मैं अभी भी एमएमएस हिस्सा भेजने पर काम कर रहा हूँ चाहता हूँ।

+0

DATE_TAKEN के लिए मूल्य क्या है? – blackjack

+2

@blackjack यह MediaStore.Images.ImageColumns.DATE_TAKEN – jimmithy

+0

ध्यान दें कि यह अब पुराना हो गया है: 'प्रबंधितQuery' को हनीकॉम (एंड्रॉइड 3.0) से हटा दिया गया है। –

2

द्वारा https://stackoverflow.com/a/20065920/763459

प्रेरित होकर ताकि जवाब में मुख्य चिंता का विषय नहीं सभी उपकरणों "DCIM" कैमरा फ़ोल्डर के रूप में प्रयोग कर रहे हैं था। तब मुझे पता चला कि अगर कोई ऐप-निर्दिष्ट फ़ोल्डर के अंदर एक फ़ाइल स्थित है, तो इसे ContentResolver द्वारा अनुक्रमित किया जाएगा, लेकिन अन्य ऐप के पास इसका उपयोग नहीं है, जिसका अर्थ है canRead=false। तो यहां मैं एक और समाधान के साथ आया:

while (cursor.moveToNext()) { 
     String imagePath = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA)); 
     File imageFile = new File(imagePath); 
     if (imageFile.canRead() && imageFile.exists()) { 
      // we have found the latest picture in the public folder, do whatever you want 
      break; 
     } 
    } 
संबंधित मुद्दे

 संबंधित मुद्दे