当前位置: 首页 > 工具软件 > IPMsg4Android > 使用案例 >

android短信发送,和状态

苏墨竹
2023-12-01

  
  
 
  
  // TODO Auto-generated method stub
  SmsManager smsManager = SmsManager.getDefault(); 
  List<String> divideContents = smsManager.divideMessage(EditSmsContent.getText().toString());   
  String SENT_SMS_ACTION = "SENT_SMS_ACTION"; 
  Intent sentIntent = new Intent(SENT_SMS_ACTION); 
  PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 
          0); 
  // register the Broadcast Receivers 
  this.registerReceiver(new BroadcastReceiver() { 
      @Override 
      public void onReceive(Context _context, Intent _intent) { 
          switch (getResultCode()) { 
          case Activity.RESULT_OK: 
              Toast.makeText(_context, 
          "���ŷ��ͳɹ�", Toast.LENGTH_SHORT) 
          .show(); 
            
          break; 
          case SmsManager.RESULT_ERROR_GENERIC_FAILURE: 
          break; 
          case SmsManager.RESULT_ERROR_RADIO_OFF: 
          break; 
          case SmsManager.RESULT_ERROR_NULL_PDU: 
          break; 
          } 
      } 
  }, new IntentFilter(SENT_SMS_ACTION));
  
  
  String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; 
  // create the deilverIntent parameter 
  Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); 
  PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, 
         deliverIntent, 0); 
  this.registerReceiver(new BroadcastReceiver() { 
     @Override 
     public void onReceive(Context _context, Intent _intent) { 
         Toast.makeText(_context, 
    "�������Ѿ��ɹ�����", Toast.LENGTH_SHORT) 
    .show(); 
         EditSmsContent.setText("");
         send=true;
     } 
  }, new IntentFilter(DELIVERED_SMS_ACTION));
  
  insertSendSmsData(Number, EditSmsContent.getText().toString(), send);
  listInit();
  for (String text : divideContents) {   
      smsManager.sendTextMessage(Number, null, text, sentPI, deliverPI);   
  }
 
 
 
public static final String SMS_URI_ALL = "content://sms/";
    private boolean send=false;
   
    private void insertSendSmsData(String sentNumber, String sentContent, boolean isImmediateSend){
//  if(mTimingSmsModel != null){
   ContentValues values = new ContentValues();
   values.put(SmsField.ADDRESS, sentNumber);
   values.put(SmsField.PERSON, 0);
   if(isImmediateSend){
    Date nowTime = new Date();
    values.put(SmsField.DATE, nowTime.getTime());
   }
//   else{
//    values.put(SmsField.DATE, mTimingSmsModel.getTimeMillis());
//   }
   values.put(SmsField.DATE_SENT, 0);
   values.put(SmsField.READ, 1);
   values.put(SmsField.STATUS, -1);
   values.put(SmsField.TYPE, 2);
   values.put(SmsField.BODY, sentContent);
   values.put(SmsField.LOCKED, 0);
//   values.put(SmsField.SIM_ID, mTimingSmsModel.getSimCardId());
   values.put(SmsField.ERROR_CODE, 0);
   values.put(SmsField.SEEN, 1);
   values.put(SmsField.SEEN, 1);
   values.put(SmsField.IPMSG_ID, 0);
   getContentResolver().insert(Uri.parse(SMS_URI_ALL), values);
  }
 
 
 
 public class SmsField{
 public static final String ADDRESS     = "address";
 public static final String PERSON     = "person";
 public static final String DATE     = "date";
 public static final String DATE_SENT    = "date_sent";
 public static final String PROTOCOL    = "protocol";
 public static final String READ     = "read";
 public static final String STATUS     = "status";
 public static final String TYPE     = "type";
 public static final String REPLY_PATH_PRESENT  = "reply_path_present";
 public static final String SUBJECT     = "subject";
 public static final String BODY     = "body";
 public static final String SERVICE_CENTER   = "service_center";
 public static final String LOCKED     = "locked";
 public static final String SIM_ID     = "sim_id";
 public static final String ERROR_CODE    = "error_code";
 public static final String SEEN     = "seen";
 public static final String IPMSG_ID    = "ipmsg_id";
}
 类似资料: