user2121 user2121 - 1 month ago 10
Android Question

Implicit Intent causes the App to crash

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 the email address, and in the second
textview
he should enter the email address of the recipient, and when he clicks on the
button
, all the component registered for the
Action
SEND
should appear including my app.

Below is my attempts and the
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)

Answer

ACTION_SEND does not use setData() -- please remove that.

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.