如何发送短信?这看起来很简单,但对我来说不起作用。
我在清单中获得了许可:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.healthapp.healthapp">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application ...
Run Code Online (Sandbox Code Playgroud)
然后我的 onClick 中有这段代码:
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("07123456789", null, "Hello there!", null, null);
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个程序时,我得到“不幸的是应用程序已停止”。
以及错误消息:
FATAL EXCEPTION: main
Process: com.healthapp.healthapp, PID: 13477
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW typ=vnd.android-dir/mms-sms (has extras) }
Run Code Online (Sandbox Code Playgroud)