我正在使用Android应用程序,我正在使用SMS功能。为此,我使用意图启动本机短信功能的活动。
我的代码如下所示,但它在以下情况下给出了以下异常:
代码:
Intent intent_sms = new Intent(Intent.ACTION_MAIN);
intent_sms.setType("vnd.android-dir/mms-sms");
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP |Intent.FLAG_ACTIVITY_CLEAR_TOP;
intent_sms.setFlags(flags);
intent_sms.setData(Uri.parse("content://sms/inbox"));
startActivity(intent_sms);
错误日志:
01-17 07:40:41.261: E/AndroidRuntime(7674):
android.content.ActivityNotFoundException:
No Activity found to handle Intent { act=android.intent.action.MAIN
dat=content://sms/inbox flg=0x34000000 }
答案 0 :(得分:0)
试试这个......
Intent intent_sms = new Intent(Intent.ACTION_VIEW);
intent_sms.setData(Uri.parse("sms:"));
intent_sms.putExtra("sms_body", "Hello");
startActivity(intent_sms);
答案 1 :(得分:0)
您可以尝试以下代码打开收件箱:
Intent intent_sms = new Intent(Intent.ACTION_MAIN);
intent_sms.addCategory(Intent.CATEGORY_LAUNCHER);
intent_sms.setClassName("com.android.mms",
"com.android.mms.ui.ConversationList");
startActivity(intent_sms);
答案 2 :(得分:0)
试试这段代码:
@TargetApi(Build.VERSION_CODES.KITKAT)
protected void idClicked() {
Intent smsIntent;
// At least KitKat
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Need to change the build to API 19
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity());
smsIntent = new Intent(Intent.ACTION_SEND);
smsIntent.setType("text/plain");
smsIntent.putExtra(Intent.EXTRA_TEXT, mText);
// Can be null in case that there is no default, then the user would be able to choose
// any app that support this intent.
if (defaultSmsPackageName != null) {
smsIntent.setPackage(defaultSmsPackageName);
}
startActivity(smsIntent);
// Older versions
} else {
smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("sms_body", mText);
if (smsIntent.resolveActivity(getActivity().getPackageManager()) != null) {
startActivity(smsIntent);
} else {
UIUtils.showShortToast(getString(R.string.no_sms_app), getActivity());
}
}
}