我正在將應用程序的以下代碼與共享共享。在可繪製文件夾中共享png圖像
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
這是在繪製文件夾中。但圖像無法發送。是因爲在setType中,它是image/jpeg?我無法使用jpeg,因爲它失去了透明度。有人可以建議我如何與圖像分享?
這裏是我使用的圖像複製從繪製到SD卡的代碼:
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