Trigger SMS Application for sending the Sms, that is support for all version of Android
protected void sendSMS(String sms) { if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) //At least KitKat { String defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(getActivity()); //Need to change the build to API 19 Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.setType("text/plain"); sendIntent.putExtra(Intent.EXTRA_TEXT, sms); if (defaultSmsPackageName != null)//Can be null in case that there is no default, then the user would be able to choose any app that support this intent. { sendIntent.setPackage(defaultSmsPackageName); } startActivity(sendIntent); } else //For early versions, do what worked for you before. { Intent sendIntent = new Intent(Intent.ACTION_VIEW); sendIntent.setData(Uri.parse("sms:")); sendIntent.putExtra("sms_body", sms); startActivity(sendIntent); } } else { Toast.makeText(getActivity(), "SMS service not available", Toast.LENGTH_SHORT).show(); } }
No comments:
Post a Comment