// At least KitKat, KitKat系统使用的是hangout来分享.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// Need to change the build to API 19
String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context);
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.setType("text/plain");
// 传递文本内容
sendIntent.putExtra(Intent.EXTRA_TEXT, "你的文字内容");
// 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) {
sendIntent.setPackage(defaultSmsPackageName);
}
// context, 你懂的.
context.startActivity(sendIntent);
}
在nexus 5上测试成功。图片分享没有用到,有需要的自己弄吧。
本文介绍了一种在KitKat及以上版本的Android系统中通过默认短信应用分享文本的方法。通过设置发送意图并指定文本类型,可以调用系统的分享功能。如果设备上有默认的短信应用,则可以直接指定该应用进行分享。

被折叠的 条评论
为什么被折叠?



