Bah*_*man 0 sms android android-intent
I am using this code to send sms:
This code could be found in many tutorials but it is not working in Oreo, i have sent the correct answer
public void sendSms(String phone) {
if(null != phone) {
final Intent i = new Intent(Intent.ACTION_VIEW);
i.setType("vnd.android-dir/mms-sms");//<-- maybe problem is here
i.putExtra("address", phone);
startActivity(Intent.createChooser(i, getString(R.string.sms)));
}
}
Run Code Online (Sandbox Code Playgroud)
I have tested this code in Android 4 to Android 6 and no problem but in Android 8.1 google api emulator says no app can perform this action, but this emulator already has SMS app installed
Also i do not know if this is working in real devices with Oreo 8.1
如果你想让用户在这部分不输入电话号码就去发送短信
Uri.parse("smsto: " + phone),让他在去奥利奥发送短信之前选择联系人,你可以在奥利奥及更低版本中使用此代码:
Intent sendIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("sms:"));
sendIntent.putExtra("sms_body", "your message");
if(android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
sendIntent.setType("vnd.android-dir/mms-sms");
context.startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1779 次 |
| 最近记录: |