我正在将应用程序的以下代码与共享共享。在可绘制文件夹中共享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