Java 如何给自己发短信

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.

如何在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:
  • 电报中间人,对于电报:

如果SMS不是强制性的,您也可以向自己发送聊天信息

实现这一目标的两个项目:

  • Nimrod,用于Facebook Messenger:
  • 电报中间人,对于电报:

这不是我想要的。I phoneNo=我的设备?。给我自己的消息?示例ContentValues=新ContentValues();价值。投入(“地址”,“123456789”);价值。put(“body”、“foo bar”);getContentResolver().insert(Uri.parse(“content://sms/sent价值观);Intent sendIntent=新的Intent(Intent.ACTION\u SENDTO,Uri.parse(“sms://”);星触觉(sendIntent);只是不想马上看消息,想呆在通知栏里。这不是我想要的。I phoneNo=我的设备?。给我自己的消息?示例ContentValues=新ContentValues();价值。投入(“地址”,“123456789”);价值。put(“body”、“foo bar”);getContentResolver().insert(Uri.parse(“content://sms/sent价值观);Intent sendIntent=新的Intent(Intent.ACTION\u SENDTO,Uri.parse(“sms://”);星触觉(sendIntent);只是不想立即阅读邮件,不想停留在通知栏中。意味着您需要在收件箱中发送此通知?您不能在收件箱中存储通知。通知仅用于通知。您可以使用notification manager通知您自己,或者使用SMS manager将此短信存储到收件箱中。如何使用SMS manager并将此短信存储到收件箱中?帮助。感谢您提供的所有答案。是否意味着您需要在收件箱中发送此通知?您不能在收件箱中存储通知。通知仅用于通知。您可以使用notification manager通知您自己,或者使用SMS manager将此短信存储到收件箱中。如何使用SMS manager并将此短信存储到收件箱中?谢谢你给我所有的答案。