में एक पीएनजी छवि साझा करना मैं ऐप के लिए निम्न कोड के साथ शेयर को एकीकृत कर रहा हूं।ड्रॉबल फ़ोल्डर
private void socialShare()
{
Uri uri = Uri.parse("android.resource://com.example.myproject/drawable/appicon");
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
shareIntent.putExtra(Intent.EXTRA_TEXT, "sharing myapp");
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, "Share from"));
}
उपरोक्त कोड में रूप में, मैं png image
जो drawable फ़ोल्डर में है डाल करने के लिए कोशिश कर रहा हूँ। लेकिन छवि भेजने में असमर्थ है। क्या ऐसा इसलिए है क्योंकि सेट टाइप में, यह छवि/जेपीईजी है? मैं जेपीईजी का उपयोग नहीं कर सकता, क्योंकि यह पारदर्शिता खो देता है। क्या कोई मुझे सुझाव दे सकता है कि छवि के साथ कैसे साझा करें?
यहाँ कोड है कि मैं drawable से sdcard के लिए चित्र को कॉपी करने के लिए उपयोग है:
String commonPath = Environment.getExternalStorageDirectory().toString() + "/MyAppFolder";
File direct = new File(commonPath);
if(!direct.exists())
{
if(direct.mkdir())
{
Log.d("tag","directory created");
//directory is created;
}
}
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.sharingimage);
OutputStream outStream = null;
File savingFile = new File(commonPath, "shareImage.png");
if(!savingFile.exists())
{
Log.d("tag","file is created");
try {
savingFile.createNewFile();
outStream = new FileOutputStream(savingFile);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Log.d("tag","Saved");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
आपके उत्तर के लिए धन्यवाद। लेकिन मैं इसे पहले तरीके से बनाने में असमर्थ हूं। – rick
क्या आपने छवि को बाहरी स्टोरेज –
नंबर में कॉपी किया है। मैं छवि की प्रतिलिपि बनाने में असमर्थ हूं। यह हमेशा फ़ाइल को अपवाद नहीं मिला फेंकता है। क्या आप कृपया मुझे कोड स्निपेट दिखा सकते हैं यदि आपके पास पहले से ही है? – rick