美文网首页
调用短信功能

调用短信功能

作者: YuGoal | 来源:发表于2017-11-08 14:43 被阅读17次
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(this); //Need to change the build to API 19
                Intent sendIntent = new Intent(Intent.ACTION_SEND);
                sendIntent.setType("text/plain");
                sendIntent.putExtra(Intent.EXTRA_TEXT, smsBody);
                if (defaultSmsPackageName != null) {
                    sendIntent.setPackage(defaultSmsPackageName);
                }
                startActivity(sendIntent);
            } else {
                Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                sendIntent.setData(Uri.parse("sms:"));
                sendIntent.putExtra("sms_body", smsBody);
                startActivity(sendIntent);
            }
    

    相关文章

      网友评论

          本文标题:调用短信功能

          本文链接:https://www.haomeiwen.com/subject/ptxymxtx.html