Android で自分に SMS を送信するにはどうすればよいですか? 送信者と架空のコンテンツを入力して、SMS 通知バーに表示させたい。
6664 次
3 に答える
3
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("DESTINATION NUMBER", null, "Your Message Text", null, null);
また、Androidマニフェストファイルに次の権限を追加します。
uses-permission android:name="android.permission.SEND_SMS"
または、160文字を超えるSMSを送信する場合:
String phoneNo = "INSERT NR HERE";
String message = "This is a long message that is supposed to be longer than 160 characters.";
SmsManager smsManager = SmsManager.getDefault();
ArrayList msgparts = smsManager.divideMessage(message);
smsManager.sendMultipartTextMessage(phoneNo, null, msgparts, null, null);
于 2012-09-20T01:12:37.123 に答える
1
自分自身にメッセージを送信したい場合は、通知マネージャーを使用できます。
通知を受け取りたい場合は、以下の関数を呼び出します。この通知のメッセージ文字列とタイトル文字列を渡します。 ここにあなたのための良いチュートリアルがあります
特定のタスクが完了した後またはその間にこの通知を送信するには、 Pending Intentも必要です。Pending Intent
外部アプリケーションがアプリケーションの権限を使用して、定義済みのコードを実行できるようにします。
これがあなたを助けるかもしれないコードです。
protected void sendnotification (String title, String message) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int icon = R.drawable.icon;
CharSequence tickerText = message;
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = title;
CharSequence contentText = message;
Intent notificationIntent = new Intent(this, YourActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
mNotificationManager.notify(1, notification);
}
于 2012-09-20T11:23:32.887 に答える
0
SMS が必須でない場合は、自分自身にチャット メッセージを送信することもできます。
これを達成する2つのプロジェクト:
- Facebookメッセンジャー用ニムロッド:https ://www.nimrod-messenger.io/
- Telegram の Telegram Middleman : https://github.com/n1try/telegram-middleman-bot
于 2017-10-13T14:49:09.030 に答える