Java 如何给自己发短信
如何在Android上向自己发送短信?我想输入一个发件人和虚构的内容,并将其显示在短信通知栏中Java 如何给自己发短信,java,android,sms,Java,Android,Sms,如何在Android上向自己发送短信?我想输入一个发件人和虚构的内容,并将其显示在短信通知栏中 SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage("DESTINATION NUMBER", null, "Your Message Text", null, null); 另外,在Android清单文件中,添加以下权限: uses-permission android:name="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);
另外,在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);
如果您想向自己发送消息,则可以使用。
当您想要得到通知时,调用下面的函数。传递此通知的消息字符串和标题字符串 您还需要在特定任务完成后或执行期间发送此通知<代码>挂起意图允许外部应用程序使用应用程序的权限执行预定义的代码。
下面是可能对您有所帮助的代码
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);
}
如果您想向自己发送消息,则可以使用。
当您想要得到通知时,调用下面的函数。传递此通知的消息字符串和标题字符串 您还需要在特定任务完成后或执行期间发送此通知<代码>挂起意图允许外部应用程序使用应用程序的权限执行预定义的代码。
下面是可能对您有所帮助的代码
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不是强制性的,您也可以向自己发送聊天信息 实现这一目标的两个项目:
- Nimrod,用于Facebook Messenger:
- 电报中间人,对于电报:
- Nimrod,用于Facebook Messenger:
- 电报中间人,对于电报: