KCR*_*aju 18 android mms bitmap
我有这个代码:
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
哪个将成功在Android上启动消息应用程序.
但是,如何在启动意图时附加Bitmap对象?
我已经阅读了http://developer.android.com/reference/Android/content/Intent.html,我需要的东西就是EXTRA_STREAM,就像这样:
intent2.putExtra(Intent.EXTRA_STREAM,_uri);
但我的情况是,我有一个Bitmap对象的引用,而不是Bitmap的URI.
请告诉我如何附加Bitmap对象?
Sag*_*yad 26
String pathofBmp = Images.Media.insertImage(getContentResolver(), bitmap,"title", null);
Uri bmpUri = Uri.parse(pathofBmp);
final Intent emailIntent1 = new Intent( android.content.Intent.ACTION_SEND);
emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent1.putExtra(Intent.EXTRA_STREAM, bmpUri);
emailIntent1.setType("image/png");
Run Code Online (Sandbox Code Playgroud)
位图是你的位图对象,必须存储在SD卡中.然后使用该Uri进行共享图像.
Gil*_* SH 22
您必须先将位图保存到文件中.您可以将其保存到应用程序的缓存中
private void shareBitmap (Bitmap bitmap,String fileName) {
try {
File file = new File(getContext().getCacheDir(), fileName + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();
file.setReadable(true, false);
final Intent intent = new Intent( android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
intent.setType("image/png");
startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26375 次 |
| 最近记录: |