diff options
author | Tom Taylor <tomtaylor@google.com> | 2011-08-11 14:35:31 -0700 |
---|---|---|
committer | Tom Taylor <tomtaylor@google.com> | 2011-08-15 10:56:08 -0700 |
commit | 6d38b19aa9aef46afa855187f23e44d4c06f8878 (patch) | |
tree | 626c2cb14ae1ac1d4d826245bb5fa4220b43fcd9 /apptests | |
parent | 4f59ce252207e067b2c06a48dc65c6338a16dab6 (diff) | |
download | packages_apps_Mms-6d38b19aa9aef46afa855187f23e44d4c06f8878.zip packages_apps_Mms-6d38b19aa9aef46afa855187f23e44d4c06f8878.tar.gz packages_apps_Mms-6d38b19aa9aef46afa855187f23e44d4c06f8878.tar.bz2 |
Add new send sms intent
Add a new intent to send an sms message without any UI interaction.
Presently, the Messaging app can already respond to intents with
the android.intent.action.SENDTO action, but this brings up the
ComposeMessageActivity primed with a destination and message. It's up
to the user to review the message and hit send. This new intent will
send the message to the user without the user seeing the compose screen
and having to hit send. Apps could already send sms's by talking
directly to the SmsManager. Using this new intent, however, has the
benefit of adding the outgoing message to a thread so the user will
be able to see what was sent. In addition, sending a message via the
Messaging app compare to the SmsManager will add automatica retry when
there's no connection, etc. This new feature could be used by the phone
app so the user could easily respond to an incoming phone call by sending a canned sms that
reads, "I'm busy, but I'll call you right back." A caller of this new
intent must have android.permission.SEND_SMS_NO_CONFIRMATION. An
accompanying CL adds the private permission to the framework.
An included test app tests the feature. Bug 4563486
Change-Id: I9292ea6d52e135cdabcfe68091d4d24d15524c97
Signed-off-by: Tom Taylor <tomtaylor@google.com>
Diffstat (limited to 'apptests')
-rw-r--r-- | apptests/Android.mk | 20 | ||||
-rw-r--r-- | apptests/AndroidManifest.xml | 41 | ||||
-rw-r--r-- | apptests/res/layout/sms_send_intent_test.xml | 66 | ||||
-rw-r--r-- | apptests/res/values/strings.xml | 33 | ||||
-rw-r--r-- | apptests/src/com/android/mms/tests/SmsSendIntentTestActivity.java | 117 |
5 files changed, 277 insertions, 0 deletions
diff --git a/apptests/Android.mk b/apptests/Android.mk new file mode 100644 index 0000000..0783ea6 --- /dev/null +++ b/apptests/Android.mk @@ -0,0 +1,20 @@ +# Copyright 2007-2008 The Android Open Source Project + +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_MODULE_TAGS := optional + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := MmsAppTests + +# Builds against the public SDK +#LOCAL_SDK_VERSION := current + +LOCAL_STATIC_JAVA_LIBRARIES += android-common jsr305 + +include $(BUILD_PACKAGE) + +# This finds and builds the test apk as well, so a single make does both. +include $(call all-makefiles-under,$(LOCAL_PATH)) diff --git a/apptests/AndroidManifest.xml b/apptests/AndroidManifest.xml new file mode 100644 index 0000000..da4d9a7 --- /dev/null +++ b/apptests/AndroidManifest.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2008 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- package name must be unique so suffix with "tests" so package loader doesn't ignore us --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.android.mms.tests"> + + <!-- By removing this permission and building and running the app, you can test + that the new SendIntent works because the app will crash because no service + to handle the intent (without SEND_SMS permission) can be found. --> + <uses-permission android:name="android.permission.SEND_SMS_NO_CONFIRMATION" /> + + <!-- We add an application tag here just so that we can indicate that + this package needs to link against the android.test library, + which is needed when building test cases. --> + <application + android:label="@string/activity_label" > + + <activity android:name=".SmsSendIntentTestActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + </activity> + </application> + +</manifest> diff --git a/apptests/res/layout/sms_send_intent_test.xml b/apptests/res/layout/sms_send_intent_test.xml new file mode 100644 index 0000000..43ac45e --- /dev/null +++ b/apptests/res/layout/sms_send_intent_test.xml @@ -0,0 +1,66 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2010 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!-- Demonstrates sending and receiving SMS messages. + See corresponding Java code SmsMessagingDemo.java +--> + +<ScrollView + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="6dip"> + <TableLayout + android:padding="6dip" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:stretchColumns="1"> + <TableRow android:layout_width="match_parent"> + <TextView android:text="@string/sms_recipient_label" /> + <EditText android:id="@+id/sms_recipient" /> + </TableRow> + <TableRow> + <TextView android:text="@string/sms_content_label" /> + <EditText android:id="@+id/sms_content" + android:scrollHorizontally="true" /> + </TableRow> + </TableLayout> + <Button + android:id="@+id/sms_send_message" + android:text="@string/sms_send_message" + android:layout_width="150dip" + android:layout_height="wrap_content" /> + <Button + android:id="@+id/sms_send_multi_message" + android:text="@string/sms_send_multi_message" + android:layout_width="150dip" + android:layout_height="wrap_content" /> + <Button + android:id="@+id/sms_send_long_message" + android:text="@string/sms_send_long_message" + android:layout_width="150dip" + android:layout_height="wrap_content" /> + <Button + android:id="@+id/sms_prime_message" + android:text="@string/sms_prime_message" + android:layout_width="150dip" + android:layout_height="wrap_content" /> + </LinearLayout> +</ScrollView> diff --git a/apptests/res/values/strings.xml b/apptests/res/values/strings.xml new file mode 100644 index 0000000..ef4a45a --- /dev/null +++ b/apptests/res/values/strings.xml @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +--> + +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <string name="sms_recipient_label">Recipient #</string> + <string name="sms_content_label">Message Body</string> + <string name="sms_send_message">Send</string> + <string name="sms_send_multi_message">Send five messages</string> + <string name="sms_send_long_message">Send a long message</string> + <string name="sms_prime_message">Prime a long message</string> + <string name="sms_long_message">Now is the time for all good men to come to the aid of their country.</string> + <string name="reply">Reply</string> + <string name="dismiss">Dismiss</string> + <string name="activity_label">Sms Tester</string> + +</resources> + diff --git a/apptests/src/com/android/mms/tests/SmsSendIntentTestActivity.java b/apptests/src/com/android/mms/tests/SmsSendIntentTestActivity.java new file mode 100644 index 0000000..6236d46 --- /dev/null +++ b/apptests/src/com/android/mms/tests/SmsSendIntentTestActivity.java @@ -0,0 +1,117 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.mms.tests; + +import java.util.List; + +import android.app.Activity; +import android.app.PendingIntent; +import android.content.Intent; +import android.net.Uri; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.android.mms.tests.R; + +// This is a manual test application for testing the Messaging app's ability to send Sms messages +// without the user having to confirm or press a send button. This app uses the intent: +// com.android.mms.intent.action.SENDTO_NO_CONFIRMATION +// to tell the messaging app to send a message. This app tests that the required permissions +// are checked. It also has buttons for testing sending a long (i.e. greater than 140 char) message +// and for sending a number of messages in rapid fire succession. + +public class SmsSendIntentTestActivity extends Activity { + /** Tag string for our debug logs */ + private static final String TAG = "SmsSendIntentTestActivity"; + private EditText mRecipient; + private EditText mMessage; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.sms_send_intent_test); + + mRecipient = (EditText)findViewById(R.id.sms_recipient); + mMessage = (EditText)findViewById(R.id.sms_content); + + mRecipient.setText("650-278-2055"); // use this to prime a number + + Button sendButton = (Button) findViewById(R.id.sms_send_message); + sendButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + sendMessage(1, 1); + } + }); + + Button sendMultiButton = (Button) findViewById(R.id.sms_send_multi_message); + sendMultiButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + sendMessage(5, 1); + } + }); + + Button sendLongButton = (Button) findViewById(R.id.sms_send_long_message); + sendLongButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + sendMessage(1, 10); + } + }); + + Button primeButton = (Button) findViewById(R.id.sms_prime_message); + primeButton.setOnClickListener(new OnClickListener() { + public void onClick(View v) { + mMessage.setText(R.string.sms_long_message); + } + }); + } + + private void sendMessage(int count, int dupeCount) { + String recipient = mRecipient.getText().toString(); + if (TextUtils.isEmpty(recipient)) { + Toast.makeText(SmsSendIntentTestActivity.this, "Please enter a message recipient.", + Toast.LENGTH_SHORT).show(); + return; + } + String message = mMessage.getText().toString(); + if (TextUtils.isEmpty(message)) { + Toast.makeText(SmsSendIntentTestActivity.this, "Please enter a message body.", + Toast.LENGTH_SHORT).show(); + return; + } + + if (dupeCount > 1) { + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < dupeCount; i++) { + sb.append(i).append(": ").append(message).append(' '); + } + message = sb.toString(); + } + Uri uri = Uri.fromParts("smsto", recipient, null); + for (int i = 0; i < count; i++) { + Intent intent = new Intent("com.android.mms.intent.action.SENDTO_NO_CONFIRMATION", uri); + intent.putExtra(Intent.EXTRA_TEXT, message); + startService(intent); + } + } +} |