2015-10-19 13 views
7

के माध्यम से बिटमैप साझा करना मेरे एंड्रॉइड ऐप में, मेरे पास बिटमैप (बी कहें) और एक बटन है। अब जब मैं बटन पर क्लिक करता हूं, तो मैं बिटमैप साझा करना चाहता हूं। मैं इस लक्ष्य को हासिल करने के लिए अपने onClick() अंदर नीचे कोड का इस्तेमाल कर रही हूँ: -एंड्रॉइड इंटेंट

Intent intent = new Intent(Intent.ACTION_SEND); 
intent.setType("image/png"); 
intent.putExtra(Intent.EXTRA_STREAM, b); 
startActivity(Intent.createChooser(intent , "Share")); 

मैं सभी आवेदन जो इस आशय को संभालने में सक्षम हैं, लेकिन मैं कुछ भी नहीं मिलता है की एक सूची उम्मीद कर रहा था। ऐप्स की कोई सूची नहीं है और न ही एंड्रॉइड स्टूडियो में कोई त्रुटि है। मेरा आवेदन बस कुछ समय के लिए फांसी हो जाती है और फिर छोड़ देता है।

मैंने बिटमैप की जांच की है और यह ठीक है (इसकी शून्य नहीं है)।

मैं कहां गलत हो रहा हूं?

उत्तर

4

the documentation का हवाला देते हुए:

एक सामग्री: यूआरआई आशय से संबद्ध डेटा ACTION_SEND के साथ इस्तेमाल किया डेटा की आपूर्ति करने की एक धारा पकड़े भेजा जा रहा है।

b, इसलिए, एक Bitmap होना चाहिए नहीं है, बल्कि एक Bitmap करने के लिए एक Uri की ओर इशारा करते, एक ContentProvider द्वारा कार्य किया। उदाहरण के लिए, आप फ़ाइल में Bitmap लिख सकते हैं, फिर इसे सेवा देने के लिए FileProvider का उपयोग करें।

11

कॉमन्सवेयर ने कहा कि आपको बिटमैप में यूआरआई प्राप्त करने और अपने अतिरिक्त के रूप में पास करने की आवश्यकता है।

String bitmapPath = Images.Media.insertImage(getContentResolver(), bitmap,"title", null); 
Uri bitmapUri = Uri.parse(bitmapPath); 
... 
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri); 
+0

कार्य पूरी तरह से –

6

** अंत में मैं समाधान मिल गया **

चरण 1:। शेयर ब्लॉक से निपटने आशय। यह आपको में आवेदन की सूची के साथ अपने विंडो पॉप अप होगा फोन

public void share_bitMap_to_Apps() { 

    Intent i = new Intent(Intent.ACTION_SEND); 

    i.setType("image/*"); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    /*compress(Bitmap.CompressFormat.PNG, 100, stream); 
    byte[] bytes = stream.toByteArray();*/ 


    i.putExtra(Intent.EXTRA_STREAM, getImageUri(mContext, getBitmapFromView(relative_me_other))); 
    try { 
     startActivity(Intent.createChooser(i, "My Profile ...")); 
    } catch (android.content.ActivityNotFoundException ex) { 

     ex.printStackTrace(); 
    } 


} 

चरण 2: आपके विचार परिवर्तित बिटमैप को

public static Bitmap getBitmapFromView(View view) { 
    //Define a bitmap with the same size as the view 
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(),  view.getHeight(), Bitmap.Config.ARGB_8888); 
    //Bind a canvas to it 
    Canvas canvas = new Canvas(returnedBitmap); 
    //Get the view's background 
    Drawable bgDrawable = view.getBackground(); 
    if (bgDrawable != null) 
     //has background drawable, then draw it on the canvas 
     bgDrawable.draw(canvas); 
    else 
     //does not have background drawable, then draw white background on the canvas 
     canvas.drawColor(Color.WHITE); 
    // draw the view on the canvas 
    view.draw(canvas); 
    //return the bitmap 
    return returnedBitmap; 
} 

चरण 3:

बिटमैप छवि से यूआरआई प्राप्त करने के लिए

public Uri getImageUri(Context inContext, Bitmap inImage) { 
    ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 

    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null); 
    return Uri.parse(path); 
} 
+1

android.permission.WRITE_EXTERNAL_STORAGE – appsthatmatter

2
ImageButton capture_share = (ImageButton) findViewById(R.id.share); 
capture_share.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View view) { 

    String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), bitmap,"title", null); 
    Uri bitmapUri = Uri.parse(bitmapPath); 

     Intent intent = new Intent(Intent.ACTION_SEND); 
     intent.setType("image/png"); 
     intent.putExtra(Intent.EXTRA_STREAM, bitmapUri); 
     startActivity(Intent.createChooser(intent, "Share")); 



    } 
}); 
+0

की आवश्यकता के लिए कुछ विवरण स्पष्ट समझ के लिए जवाब देने के लिए जोड़े मत भूलना। @ ललित बागेल –

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