Android4.4 无法使用“vnd.android-dir/mms-sms"处理短信意图; [英] Android4.4 can not handle sms intent with "vnd.android-dir/mms-sms"

查看:43
本文介绍了Android4.4 无法使用“vnd.android-dir/mms-sms"处理短信意图;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有一个按钮来启动默认的短信活动和除了新版本 Android 4.4(kitkat) 之外,所有 android 版本都运行良好代码如下:

My application has a button to start default sms activity and it worked perfectly fine all android version except new one, Android 4.4(kitkat) Here is the code:

public void onClick(View arg0) {
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.putExtra("address", member.getPhoneNumber().trim());
    context.startActivity(smsIntent);
}

我收到错误消息

11-08 02:08:32.815: E/AndroidRuntime(14733): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }

我知道谷歌对默认短信应用程序处理短信意图的方式进行了一些更改.但我的应用程序不是短信应用程序,但它仅具有使用收件人号码启动默认短信应用程序的功能.所以请帮忙.

I know that google made some changes on how the default sms app handles sms intents. but my app is not a sms app but it only has function to start default sms app with recipient number. so please help.

推荐答案

要启动带有数字填充的 SMS 应用程序,请使用操作 ACTION_SENDTO:

To start the SMS app with number populated use action ACTION_SENDTO:

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:" + Uri.encode(phoneNumber)));
startActivity(intent);

这将适用于 Android 4.4.它也应该适用于早期版本的 Android,但是由于 API 从未公开,因此行为可能会有所不同.如果您之前的方法没有问题,我可能会坚持使用 4.4 之前的版本并使用 ACTION_SENDTO 用于 4.4+.

This will work on Android 4.4. It should also work on earlier versions of Android however as the APIs were never public the behavior might vary. If you didn't have issues with your prior method I would probably just stick to that pre-4.4 and use ACTION_SENDTO for 4.4+.

这篇关于Android4.4 无法使用“vnd.android-dir/mms-sms"处理短信意图;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆