2011-04-05 13 views
9

शायद एक आसान सवाल है: मैं डिफ़ॉल्ट शेयर "इरादा" के साथ नेट/ट्विटर/फेसबुक/आदि पर नेट पर प्राप्त बिटमैप साझा करना चाहता हूं।एंड्रॉइड पर ट्विटर, फेसबुक, मेल

कोड मैंने पाया बिटमैप साथ बिंदु "IDONTKNOW" में भरे जाने वाले

 Intent sendIntent = new Intent(Intent.ACTION_SEND); 
     sendIntent.setType("image/jpeg"); 
     sendIntent.putExtra(Intent.EXTRA_STREAM, "IDONTKNOW"); 
     sendIntent.putExtra(Intent.EXTRA_TEXT, 
       "See my captured picture - wow :)"); 
     startActivity(Intent.createChooser(sendIntent, "share")); 

जरूरतों। (This.bitmap)

मैं कोई रास्ता नहीं आंतरिक एसडी करने के लिए बिटमैप बिना सहेजे को संभालने के लिए मिल गया ..

संबंध

+0

यह क्यू एंड ए पढ़ने लायक है http://stackoverflow.com/questions/9049143/android -श्रे-एंट-फॉर-ए-बिटमैप-यह-संभव-से-सेव-से-प्री-शेयरिंग – Suragch

उत्तर

7

बस, आप बाहरी स्टोरेज से पीएनजी में बिटमैप को परिवर्तित कर सकते हैं।

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
File imageFile = new File(path, getCurrentTime()+ ".png"); 
FileOutputStream fileOutPutStream = new FileOutputStream(imageFile); 
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream); 

fileOutPutStream.flush(); 
fileOutPutStream.close(); 

उसके बाद, आप Uri.parse के माध्यम से एक यूआरआइ प्राप्त कर सकते हैं:

return Uri.parse("file://" + imageFile.getAbsolutePath()); 
+0

स्ट्रिंग पथ = पर्यावरण .getExternalStoragePublicDirectory (Environment.DIRECTORY_PICTURES); –

1

ठीक है मैं इसे अपने दम पर मिला है, यह वहाँ लगता है पाने के लिए कोई रास्ता नहीं है डिस्क के लिए बिटमैप सहेजे बिना छवि uri, इसलिए मैं इस सरल विधि का उपयोग करें:

private Uri storeImage() { 
    this.storedImage = null; 
    this.storeImage = true; 
    // Wait for the image 
    while (this.storedImage == null && !this.stop) 
     try { 
      Thread.sleep(100); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
    this.storeImage = false; 
    FileOutputStream fileOutputStream = null; 
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
    File file = new File(path, "cwth_" + getCurrentTime()+ ".jpg"); 
    try { 
     fileOutputStream = new FileOutputStream(file); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 
    BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream); 
    this.storedImage.compress(CompressFormat.JPEG, JPEG_STORE_QUALITY, bos); 
    try { 
     bos.flush(); 
     bos.close(); 
     fileOutputStream.flush(); 
     fileOutputStream.close(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return Uri.parse("file://" + file.getAbsolutePath()); 
} 
4

एक छोटे से देर से अब है, लेकिन आप भी String url = Images.Media.insertImage(context.getContentResolver(), image, "title", null); कर सकता है अगर आप परवाह नहीं है कि यह कैसे संग्रह किया गया है।

+0

यह विधि छवि के लिए थंबनेल बनाएं (दस्तावेज़ीकरण के रूप में)। – wisemann

-2

बाइनरी सामग्री भेजें बाइनरी डेटा ACTION_SEND कार्रवाई उचित MIME प्रकार स्थापित करने और करने के लिए यूआरआई रखने के साथ संयुक्त का उपयोग कर साझा किया जाता है अतिरिक्त नाम EXTRA_STREAM में डेटा। यह आमतौर पर एक छवि साझा करने के लिए प्रयोग किया जाता है लेकिन द्विआधारी सामग्री में किसी भी प्रकार साझा करने के लिए इस्तेमाल किया जा सकता:

Intent shareIntent = new Intent(); 
shareIntent.setAction(Intent.ACTION_SEND); 
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage); 
shareIntent.setType("image/jpeg"); 
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to))); 

स्रोत http://developer.android.com/training/sharing/send.html

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