安卓分享通过对话

2023-09-11 20:16:21 作者:迀就你一生

我通过共享对话框是像TFLN(文本从昨晚)的应用程序见过了。 看起来是这样的:

I've seen the "share via" dialogs that are in apps like TFLN (texts from last night). Looks like this:

我期待共享文本。有人能指出我朝着正确的方向吗?这是做了与意图?

I am looking to share text. Can someone point me in the right direction? Is this done with intents?

推荐答案

这的确是与意图完成。

有关共享图像,比如上例中的图片,这将是这样的:

For sharing an image, like in the example picture, it would be something like this:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");

share.putExtra(Intent.EXTRA_STREAM,
  Uri.parse("file:///sdcard/DCIM/Camera/myPic.jpg"));

startActivity(Intent.createChooser(share, "Share Image"));

有关文字,你会使用这样的:

For text you would use something like:

Intent share = new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT, "I'm being sent!!");
startActivity(Intent.createChooser(share, "Share Text"));
相关推荐