我正在将共享与应用程序的以下代码集成。
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,因为它失去了透明度。有人可以建议我如何与图像分享吗?
这是我用来将图像从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();
}
}