“android.intent.extra.STREAM”

发布于 2024-11-04 12:47:05 字数 406 浏览 2 评论 0原文

在进行一些研发时发现了代码使用以下语句

Uri uri = (Uri) getIntent().getExtras().get("android.intent.extra.STREAM");

我扫描了整个项目以查找该活动是否是从任何其他活动调用的,但没有找到任何。谁能告诉我这个语句会返回什么以及代码中的语句 "android.intent.extra.STREAM" 做什么,它是否是一个常量,如果是的话它的值是什么?

提前致谢。

快乐编码

While doing some R&D I found a code using the following statement

Uri uri = (Uri) getIntent().getExtras().get("android.intent.extra.STREAM");

I have scanned the whole project to find whether the activity was called from any other activity, but did'nt find any. Can any one tell me what will this statement return and what is the statement "android.intent.extra.STREAM" doing in the code, whether it is a constant, if yes what is its value?

Thanks in advance.

Happy Coding

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

肥爪爪 2024-11-11 12:47:10

此语句将返回名为 "android.intent.extra.STREAM" 的额外内容。无论哪个活动发出意图,都会设置该值,并且如果不查看数据的使用方式或在何处/如何设置,则无法简单地判断该数据是什么。不要忘记意图可以由任何活动或应用程序发出。

找到你的答案:

public static final String EXTRA_STREAM                       Since: API Level 1

A content: URI holding a stream of data associated with the Intent, used with 
ACTION_SEND to supply the data being sent.
Constant Value: "android.intent.extra.STREAM"

所以,我认为这是设计用于共享图像的意图的不良编码(使用值而不是定义的静态常量)的结果。 Intent 包含 Intent.EXTRA_STREAM extra 作为要共享的图像(在本例中)的数据流。 IMO,代码应该是:

Uri uri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);

但无论如何,它似乎是将二进制数据流附加到意图的记录/标准化方法。

持续的研究似乎表明它添加了 Campyre(Campfire 客户端)作为“共享”选项。因此,在图库中,如果您选择共享图像,Campyre 将显示为选项之一。

GoogleAndroid 开发者网站 是您的朋友。我总共花了大约 2 分钟才获得所有这些信息。不需要输入回复和后续编辑...

更多详细说明:

这是 AndroidManifest.xml 中的相关部分:

    <activity android:name=".ShareImage"
      android:theme="@android:style/Theme.Dialog"
      android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
      </intent-filter>
    </activity>

这表明 Activity 可以处理用于共享项目所在位置的 Intents共享的是图像。

This statement will return the extra named "android.intent.extra.STREAM". Whatever activity issued the intent set that value, and there's no easy way to tell what that data is without seeing how it is used, or where/how it was set. Don't forget that the intent could be issued by any activity or application.

Found your answer:

public static final String EXTRA_STREAM                       Since: API Level 1

A content: URI holding a stream of data associated with the Intent, used with 
ACTION_SEND to supply the data being sent.
Constant Value: "android.intent.extra.STREAM"

So, I would posit that it's the result of poor coding (using the value rather than the defined static constant) for an intent designed to share images. The intent includes the Intent.EXTRA_STREAM extra as the data stream for the image (in this case) to be shared. IMO, the code should have been:

Uri uri = (Uri) getIntent().getExtras().get(Intent.EXTRA_STREAM);

But regardless, it appears to be the documented/standardized way of attaching a binary datastream to an intent.

Continued research seems to indicate that it adds Campyre (a Campfire client) as a "Share" option. So from Gallery, if you choose to Share an image, Campyre shows up as one of the options.

Google and the Android dev site are your friends. It took me all of about 2 minutes total to get all that information. Not as long as it took to type the replies and subsequent edits...

More elaboration:

Here is the relevant section from AndroidManifest.xml:

    <activity android:name=".ShareImage"
      android:theme="@android:style/Theme.Dialog"
      android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.SEND" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="image/*" />
      </intent-filter>
    </activity>

Which indicates that the Activity can handle Intents for sharing where the item being shared is an image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文