ユーザーがフォームに入力し、入力した詳細をメールIDに送信できるアプリを作成しています
[Send Details] ボタンをクリックするたびに、次のメッセージが表示されます:残念ながらメッセージ ランチャーが停止しました
Java コード:
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
Button mImgViewCart = (Button) findViewById(R.id.ButtonSendFeedback);
mImgViewCart.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
final EditText nameField = (EditText) findViewById(R.id.EditTextName);
String name = nameField.getText().toString();
final EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
String email = emailField.getText().toString();
final EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);
String feedback = feedbackField.getText().toString();
final Spinner feedbackSpinner = (Spinner) findViewById(R.id.SpinnerFeedbackType);
String feedbackType = feedbackSpinner.getSelectedItem().toString();
final CheckBox responseCheckbox = (CheckBox) findViewById(R.id.CheckBoxResponse);
boolean bRequiresResponse = responseCheckbox.isChecked();
// Take the fields and format the message contents
String subject = formatFeedbackSubject(feedbackType);
String message = formatFeedbackMessage(feedbackType, name,
email, feedback, bRequiresResponse);
// Create the message
sendFeedbackMessage(subject, message);
}
});
}
protected String formatFeedbackSubject(String feedbackType) {
String strFeedbackSubjectFormat = getResources().getString(
R.string.feedbackmessagesubject_format);
String strFeedbackSubject = String.format(strFeedbackSubjectFormat, feedbackType);
return strFeedbackSubject;
}
protected String formatFeedbackMessage(String feedbackType, String name,
String email, String feedback, boolean bRequiresResponse) {
String strFeedbackFormatMsg = getResources().getString(
R.string.feedbackmessagebody_format);
String strRequiresResponse = getResponseString(bRequiresResponse);
String strFeedbackMsg = String.format(strFeedbackFormatMsg,
feedbackType, feedback, name, email, strRequiresResponse);
return strFeedbackMsg;
}
protected String getResponseString(boolean bRequiresResponse)
{
if(bRequiresResponse==true)
{
return getResources().getString(R.string.feedbackmessagebody_responseyes);
} else {
return getResources().getString(R.string.feedbackmessagebody_responseno);
}
}
public void sendFeedbackMessage(String subject, String message) {
Intent messageIntent = new Intent(android.content.Intent.ACTION_SEND);
String aEmailList[] = { "####@gmail.com" };
messageIntent.putExtra(android.content.Intent.EXTRA_EMAIL, aEmailList);
messageIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
messageIntent.setType("plain/text");
messageIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(messageIntent);
}
}
フォーム.xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<TextView
android:id="@+id/TextViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/feedbacktitle"
android:textSize="10pt"></TextView>
<EditText
android:id="@+id/EditTextName"
android:layout_height="wrap_content"
android:hint="@string/feedbackname"
android:inputType="textPersonName"
android:layout_width="fill_parent"></EditText>
<EditText
android:id="@+id/EditTextEmail"
android:layout_height="wrap_content"
android:hint="@string/feedbackemail"
android:inputType="textEmailAddress"
android:layout_width="fill_parent"></EditText>
<Spinner
android:id="@+id/SpinnerFeedbackType"
android:layout_height="wrap_content"
android:prompt="@string/feedbacktype"
android:layout_width="fill_parent"
android:entries="@array/feedbacktypelist"></Spinner>
<EditText
android:id="@+id/EditTextFeedbackBody"
android:layout_height="wrap_content"
android:hint="@string/feedbackbody"
android:inputType="textMultiLine"
android:lines="5"
android:layout_width="fill_parent"></EditText>
<CheckBox
android:id="@+id/CheckBoxResponse"
android:layout_height="wrap_content"
android:text="@string/feedbackresponse"
android:layout_width="fill_parent"></CheckBox>
<Button
android:id="@+id/ButtonSendFeedback"
android:layout_height="wrap_content"
android:text="@string/feedbackbutton"
android:layout_width="fill_parent"></Button>
</LinearLayout>
</ScrollView>
マニフェスト.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.jsrrestjjjb"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.jsrrestjjjb.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>
ログキャット:
01-05 10:02:12.759: E/AndroidRuntime(920): FATAL EXCEPTION: main
01-05 10:02:12.759: E/AndroidRuntime(920): java.lang.IllegalStateException: Could not execute method of the activity
01-05 10:02:12.759: E/AndroidRuntime(920): at android.view.View$1.onClick(View.java:3597)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.view.View.performClick(View.java:4202)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.view.View$PerformClick.run(View.java:17340)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.os.Handler.handleCallback(Handler.java:725)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.os.Handler.dispatchMessage(Handler.java:92)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.os.Looper.loop(Looper.java:137)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-05 10:02:12.759: E/AndroidRuntime(920): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 10:02:12.759: E/AndroidRuntime(920): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 10:02:12.759: E/AndroidRuntime(920): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-05 10:02:12.759: E/AndroidRuntime(920): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-05 10:02:12.759: E/AndroidRuntime(920): at dalvik.system.NativeStart.main(Native Method)
01-05 10:02:12.759: E/AndroidRuntime(920): Caused by: java.lang.reflect.InvocationTargetException
01-05 10:02:12.759: E/AndroidRuntime(920): at java.lang.reflect.Method.invokeNative(Native Method)
01-05 10:02:12.759: E/AndroidRuntime(920): at java.lang.reflect.Method.invoke(Method.java:511)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.view.View$1.onClick(View.java:3592)
01-05 10:02:12.759: E/AndroidRuntime(920): ... 11 more
01-05 10:02:12.759: E/AndroidRuntime(920): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND typ=plain/text flg=0x1 (has clip) (has extras) }
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1622)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Activity.startActivityForResult(Activity.java:3370)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Activity.startActivityForResult(Activity.java:3331)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Activity.startActivity(Activity.java:3566)
01-05 10:02:12.759: E/AndroidRuntime(920): at android.app.Activity.startActivity(Activity.java:3534)
01-05 10:02:12.759: E/AndroidRuntime(920): at com.example.jsrrestjjjb.MainActivity.sendFeedbackMessage(MainActivity.java:102)
01-05 10:02:12.759: E/AndroidRuntime(920): at com.example.jsrrestjjjb.MainActivity.sendFeedback(MainActivity.java:48)
01-05 10:02:12.759: E/AndroidRuntime(920): ... 14 more