2012-09-20 132 views

回答

4
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); 
+0

是不是我多麼希望。我電話號碼=我的設備?給我自己的消息? –

+0

示例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);只是不想立即閱讀消息想要留在通知欄中。 –

1

如果您想要發送消息給自己,那麼你可以使用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); 
} 
+0

是的,很好的樣本,這是怎麼樣的短信收件箱? –

+0

表示您需要在收件箱中發送此通知? –

+0

正是我所需要的 –