我已经弄明白了如何发送和接收短信.要发送短信,我必须调用该类的sendTextMessage()和sendMultipartTextMessage()方法SmsManager.要接收SMS消息,我必须在AndroidMainfest.xml文件中注册接收器.然后我不得不重写onReceive()方法BroadcastReceiver.我在下面列举了一些例子.
MainActivity.java
public class MainActivity extends Activity {
private static String SENT = "SMS_SENT";
private static String DELIVERED = "SMS_DELIVERED";
private static int MAX_SMS_MESSAGE_LENGTH = 160;
// ---sends an SMS message to another device---
public static void sendSMS(String phoneNumber, String message) {
PendingIntent piSent = PendingIntent.getBroadcast(mContext, 0, new Intent(SENT), 0);
PendingIntent piDelivered = PendingIntent.getBroadcast(mContext, 0,new Intent(DELIVERED), 0);
SmsManager smsManager = SmsManager.getDefault();
int length = message.length();
if(length > MAX_SMS_MESSAGE_LENGTH) …Run Code Online (Sandbox Code Playgroud) 在我的Android应用程序中,我想获得所有可用的APN并检查客户端APN是否可用.我想使用此客户端APN运行我的应用程序.
有没有办法在Android上实现这一目标?