テキストメッセージを送信するにはどうすればよいですか?シンプルなようですが、それは私のためには機能しません。Androidでテキストメッセージを送信するにはどうすればよいですか?
私はマニフェストに権限を持っている:私はその後、私ののonClickでこのコードを持って
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.healthapp.healthapp">
<uses-permission android:name="android.permission.SEND_SMS"/>
<application ...
:
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);
しかし、私はこれを実行すると、私は「残念ながら、アプリケーションが停止しました。」を取得
とのエラーメッセージ:あなたはあなたのコードでSMSを送信する二つの異なる方法を持っている
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) }
ああおかげで?おそらく何かを記録することによって?または、sendTextMessageのnullパラメータの1つを使用しますか? – user2633709
さて、実際のメッセージをエミュレータから実際のデバイスに送ることはできません。しかし、4番目の引数に 'PendingIntent'を渡すことができます。これは結果のコードを含む' Intent'をターゲットコンポーネントに渡しますが、エミュレータがそれをどのように処理するかは分かりません。つまり、すべてが有効であれば実際に成功コードを提供するかどうかはわかりませんが、私はそれがすべきだと思います。私は[回答はこちら](BroadcastReceiver)の一般的な例を持っています(http://stackoverflow.com/questions/24673595/how-to-get-sms-sent-confirmation-for-each-contact-person -in-android/24845193#24845193) –
ありがとう、私はそれがPendingIntentかもしれないと思ったが、私はこれのための構文が分からない。上記でPendingIntentを以下のように定義しますか?Intent sendIntent = new Intent(Intent。ACTION_VIEW); sendTextMessageのパラメータとしてsendIntentを設定しますか? – user2633709