如何在Android上發送短信給我自己?我想輸入發件人和虛構的內容,並將其顯示在短信通知欄中。如何發送短信給我自己
回答
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("DESTINATION NUMBER", null, "Your Message Text", null, null);
在你的Android清單文件
此外,添加以下權限:
uses-permission android:name="android.permission.SEND_SMS"
或者,如果你想發送短信超過160個字符:
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);
如果您想要發送消息給自己,那麼你可以使用notification Manager。
當你想得到通知時調用下面的函數。傳遞此通知的消息字符串和標題字符串。 Here is good tutorial for you
您還需要 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);
}
是的,很好的樣本,這是怎麼樣的短信收件箱? –
表示您需要在收件箱中發送此通知? –
正是我所需要的 –
如果SMS不是強制性的,您也可以發送聊天消息給自己。
兩個項目實現這一點:
- 尼姆羅德,爲Facebook Messenger的:https://www.nimrod-messenger.io/
- 電報中間人,對電報:https://github.com/n1try/telegram-middleman-bot
- 1. 發送短信我自己
- 2. 在Android上發送短信給自己
- 3. 發送短信給自己並接收它
- 4. 可以讓一個模擬器發送短信給自己
- 5. 發送自動短信給來電
- 6. 是否可以通過我的電報機發送短信給自己?
- 7. 自動發送短信給來電和短信
- 8. 如何從iPad發送短信(短信)
- 9. 如何自動發送短信?
- 10. 如何將代碼發送給自己?
- 11. 發送自動短信
- 12. 自動發送短信
- 13. 如何發送短信
- 14. pjsip發送短信如何
- 15. 如何發送短信?
- 16. 如何發送短信
- 17. 如何不發送短信保存發送郵件後發送短信從SmsManager
- 18. Android - 嘗試發送虛假短信給自己,無需移動網絡使用
- 19. 發送短信
- 20. 發送短信
- 21. 發送短信
- 22. 發送短信
- 23. 安卓 - 刪除手機驗證短信發送到自己
- 24. 我如何發送自動短信在迅速?
- 25. android如何發送短信和彩信?
- 26. 如何在我自己的應用程序中發送彩信?
- 27. 意向短信發送給多個contactcs
- 28. 大衆短信不發送給大家
- 29. 發送短信給接收者
- 30. 發送短信給收件人iOS
是不是我多麼希望。我電話號碼=我的設備?給我自己的消息? –
示例ContentValues values = new ContentValues(); values.put(「address」,「123456789」); values.put(「body」,「foo bar」); ():content:// sms/sent「),values); \t 意圖sendIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse(「sms://」)); startActivity(sendIntent);只是不想立即閱讀消息想要留在通知欄中。 –