Android 分享意向 EXTRA_STREAM
Android Share Intent EXTRA_STREAM
我有这种共享文本文件或图片的方法,具体取决于我使用的 EXTRA_STREAM。我有这两个我可以选择
i.putExtra(Intent.EXTRA_STREAM, uri);
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
如何在调用 startActivity 时同时共享两者?
这是我的代码
public void shareTextAndPic(){
long x = getBundle();
Product product = db.findProductbyId(getBundle());
Bitmap icon = BitmapFactory.decodeByteArray(db.fetchSingle(x), 0,
db.fetchSingle(x).length);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
} catch (Exception e) {
System.err.println(e.toString());
}
//share.putExtra(Intent.EXTRA_STREAM, uri);
//startActivity(Intent.createChooser(share, "Share Image"));
File file = new File(way + "/momsfil.txt");
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "ttj@live.se" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, "body of email");
//i.putExtra(Intent.EXTRA_STREAM, uri);
try {
startActivity(Intent.createChooser(i, "Share"));
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(TableRow.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
}
我有这种共享文本文件或图片的方法,具体取决于我使用的 EXTRA_STREAM。我有这两个我可以选择
i.putExtra(Intent.EXTRA_STREAM, uri);
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
如何在调用 startActivity 时同时共享两者?
这是我的代码
public void shareTextAndPic(){
long x = getBundle();
Product product = db.findProductbyId(getBundle());
Bitmap icon = BitmapFactory.decodeByteArray(db.fetchSingle(x), 0,
db.fetchSingle(x).length);
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
} catch (Exception e) {
System.err.println(e.toString());
}
//share.putExtra(Intent.EXTRA_STREAM, uri);
//startActivity(Intent.createChooser(share, "Share Image"));
File file = new File(way + "/momsfil.txt");
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.setType("image/jpeg");
i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
i.putExtra(Intent.EXTRA_EMAIL, new String[] { "ttj@live.se" });
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT, "body of email");
//i.putExtra(Intent.EXTRA_STREAM, uri);
try {
startActivity(Intent.createChooser(i, "Share"));
} catch (android.content.ActivityNotFoundException e) {
Toast.makeText(TableRow.this,
"There are no email clients installed.",
Toast.LENGTH_SHORT).show();
}
}