隐式意图导致应用程序在按下按钮时崩溃 [英] Implicit intent causes the app to crash at button press
问题描述
为了理解隐式意图的工作原理,我想创建一个包含两个 edittext 和一个 button 的布局.在第一个 edittext 中,用户应输入他/她的电子邮件地址,在第二个 textview 中,他/她应输入收件人的电子邮件地址,以及何时输入. /she点击按钮,应该会显示为Action SEND注册的所有组件,包括我的应用程序.
In an attempt to understand how the implicit intents works, I wanted to create a layout with two edittext and one button. In the first edittext, the user should enter his/her the email address, and in the second textview he/she should enter the email address of the recipient, and when he/she clicks on the button, all the component registered for the Action SEND should appear, including my app.
下面是我的尝试和 logcat :
UPDATED_JavaCode
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String from = et_from.getText().toString();
String to = et_to.getText().toString();
String data = from + to;
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(android.content.Intent.EXTRA_TEXT, from + to);
//i.setData(Uri.parse(data.toString()));
startActivity(i);
}
});
UPDATED_Manifest :
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".EmailActivity"
android:label="@string/title_activity_intents_test01" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="CustomActivity"> </activity>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="text/plain"/>
</intent-filter>
</application>
Logcat :
11-15 14:47:19.714: E/AndroidRuntime(18239): FATAL EXCEPTION: main
11-15 14:47:19.714: E/AndroidRuntime(18239): Process: com.example.emailactivity, PID:18239
11-15 14:47:19.714: E/AndroidRuntime(18239): android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.SEND dat=yt (has extras)
}
11-15 14:47:19.714: E/AndroidRuntime(18239): at
android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1672)
11-15 14:47:19.714: E/AndroidRuntime(18239): at
android.app.Instrumentation.execStartActivity(Instrumentation.java:1442)
11-15 14:47:19.714: E/AndroidRuntime(18239): at
com.example.emailactivity.EmailActivity$1.onClick(EmailActivity.java:46)
推荐答案
ACTION_SEND
不使用setData()
-请删除它.
ACTION_SEND
does not use setData()
-- please remove that.
另外,请使用 ACTION_SEND
文档中记录的密钥支付额外费用.请注意,没有"from"
,也没有"to"
,因此您可以删除这些多余的东西.您需要提供EXTRA_TEXT
或EXTRA_STREAM
来提供您共享的实际内容.
Also, please use the keys documented in the ACTION_SEND
documentation for your extras. Note that there is no "from"
and there is no "to"
, so you can remove those extras. You will need to provide EXTRA_TEXT
or EXTRA_STREAM
to provide the actual content that you are sharing.
这篇关于隐式意图导致应用程序在按下按钮时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!