Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
哪种类型的数据被传递到我的目标android_Android_Android Intent - Fatal编程技术网

哪种类型的数据被传递到我的目标android

哪种类型的数据被传递到我的目标android,android,android-intent,Android,Android Intent,My MainActivity类包含一个EditText、一个允许用户选择图片的按钮和另一个创建第二个意图的按钮(send) 用户可以编辑编辑文本或/和选择图片。在这里,我的目的是通过使用,知道(并在第二个意图中显示)向第二个意图发送了哪种数据 我知道我必须在AndroidManifest.xml中使用它 <intent-filter> <action android:name="android.intent.action.SEND"/> <ca

My MainActivity类包含一个EditText、一个允许用户选择图片的按钮和另一个创建第二个意图的按钮(send)

用户可以编辑编辑文本或/和选择图片。在这里,我的目的是通过使用,知道(并在第二个意图中显示)向第二个意图发送了哪种数据

我知道我必须在AndroidManifest.xml中使用它

<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="image/*"/>
<data android:mimeType="text/plain"/>
</intent-filter>

但我真的不明白这一切之间有什么联系。如何使用过滤器?我必须在“发送”函数中写些什么?

您应该知道要发送的数据类型,尤其是如果您是发送数据的人。与其让单个意图操作封装多个数据类型,为什么不为每种类型创建操作呢?然后,在AndroidManifest.xml中,您可以为定义的每个操作声明一个意图过滤器。Android开发者网站对意图和意图过滤器进行了深入的概述:
// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();

// Figure out what to do based on the intent type
if (intent.getType().equals("text/plain") && intent.getType().indexOf("image/") != -1) {
    // Display "Text edited and picture picked"
else if (intent.getType().indexOf("image/") != -1) {
    // Display "Picture picked"
} else if (intent.getType().equals("text/plain")) {
    // Display "Text edited"
} else //Display "Nothing"