6
在Android中发送和接收SMS和MMS(Kit Kat之前的Android 4.4)
我已经弄清楚了如何发送和接收短信。要发送SMS消息,我必须调用类的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); …