I'm trying to send open up the messaging app to start a sms message from a widget but when I start the activity I get the "Complete action using" dialog with a long list of applications but I don't see the messaging application that I think should be the default for trying to send sms messages.
Here is my code:
public void 开发者_如何学运维onUpdate(Context context,
AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
PendingIntent smsIntent1 = PendingIntent.getActivity(context, 0, sendIntent, 0);
sendIntent.putExtra("address", "8017777777");
sendIntent.setType("vnd.android-dir/mms-sms");
views.setOnClickPendingIntent(R.id.sms_btn1, smsIntent1);
appWidgetManager.updateAppWidget(appWidgetIds, views);
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
and my manifest has this in it:
<uses-permission android:name="android.permission.SEND_SMS"/>
Any ideas? Thanks!
Most likely, the Messenger app has an <intent-filter>
that does not cover your MIME type.
I am not completely certain why you have that MIME type in there. I am also unclear whether that whole Intent
will work at all. I know this works, assuming 8017777777
is a phone number:
Intent sms=new Intent(Intent.ACTION_SENDTO, Uri.parse("tel:8017777777"));
sms.putExtra("sms_body", msg.getText().toString());
startActivity(sms);
Note that you do not need the SEND_SMS
permission in this case. You only need that if you are using SmsManager
to send the SMS directly.
Here is a project that demonstrates the above Intent
syntax, plus using SmsManager
directly, as options for how to send a text message to a contact in your contacts list.
I tried what CommonsWare said, but it didn't work, but it put me on the right track (which was using the Intent.ACTION_SENDTO. I found what I needed here: http://snipt.net/Martin/android-intent-usage/
This is what it ended up looking like:
Uri uri = Uri.parse("smsto:0800000123");
Intent it = new Intent(Intent.ACTION_SENDTO, uri);
it.putExtra("sms_body", "The SMS text");
PendingIntent smsIntent1 = PendingIntent.getActivity(context, 0, it, 0);
views.setOnClickPendingIntent(R.id.sms_btn1, smsIntent1);
精彩评论