今天在开发的过程中,遇到一个奇怪的问题,在
Nexus 系列的手机上没有办法使用Intent.ACTION_VIEW调用短信页面时会出现这个
No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }
日志。 后来谷歌了半天 总算找到一个可以解决的答案。
上代码:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(context); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND , smsToUri); sendIntent.putExtra("sms_body", shareParams.getText()); sendIntent.setType("text/plain"); if (defaultSmsPackageName != null){ sendIntent.setPackage(defaultSmsPackageName); } context.startActivity(sendIntent); } else { Intent sendIntent = new Intent(Intent.ACTION_VIEW, smsToUri); sendIntent.putExtra("sms_body", shareParams.getText()); sendIntent.setType("vnd.android-dir/mms-sms"); context.startActivity(sendIntent); }
关键是Intent.ACTION_SEND
sendIntent.setType("text/plain");
写下来作为记录