android.telephony.SmsManager.getDefault()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中android.telephony.SmsManager.getDefault()方法的一些代码示例,展示了SmsManager.getDefault()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SmsManager.getDefault()方法的具体详情如下:
包路径:android.telephony.SmsManager
类名称:SmsManager
方法名:getDefault

SmsManager.getDefault介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

public void sendTheMessage(View v) {
  Cursor c=(Cursor)contacts.getSelectedItem();
  
  if (means.getCheckedRadioButtonId()==R.id.client) {
   Intent sms=new Intent(Intent.ACTION_SENDTO,
              Uri.parse("smsto:"+c.getString(2)));
   
   sms.putExtra("sms_body", msg.getText().toString());
   
   startActivity(sms);
  }
  else {
   SmsManager
    .getDefault()
    .sendTextMessage(c.getString(2), null,
             msg.getText().toString(),
             null, null);
  }
 }
}

代码示例来源:origin: guardianproject/haven

private void beatingHeart ()
{
  PreferenceManager preferences = new PreferenceManager(mContext);
  int unicodeBeat = 0x1F493;
  String emojiString = new String(Character.toChars(unicodeBeat));
  if (!TextUtils.isEmpty(mUsername)) {
    getInstance(mContext, mUsername.trim());
    ArrayList<String> recipient = new ArrayList<>();
    recipient.add(preferences.getSmsNumber());
    sendMessage(recipient, emojiString,null);
  }
  else if (!TextUtils.isEmpty(preferences.getSmsNumber())) {
    SmsManager manager = SmsManager.getDefault();
    StringTokenizer st = new StringTokenizer(preferences.getSmsNumber(),",");
    while (st.hasMoreTokens())
      manager.sendTextMessage(st.nextToken(), null, emojiString, null, null);
  }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 SmsManager mgr=SmsManager.getDefault();
 String token=mgr.createAppSpecificSmsToken(buildPendingIntent());
 TextView tv=(TextView)findViewById(R.id.text);
 tv.setText(getString(R.string.msg, token));
}

代码示例来源:origin: guardianproject/haven

private void testNotifications ()
  {

    if (!TextUtils.isEmpty(preferences.getSignalUsername())) {
      SignalSender sender = SignalSender.getInstance(this, preferences.getSignalUsername().trim());
      ArrayList<String> recip = new ArrayList<>();
      recip.add(preferences.getSmsNumber());
      sender.sendMessage(recip, getString(R.string.signal_test_message), null);
    }
    else if (!TextUtils.isEmpty(preferences.getSmsNumber())) {

      SmsManager manager = SmsManager.getDefault();

      StringTokenizer st = new StringTokenizer(preferences.getSmsNumber(),",");
      while (st.hasMoreTokens())
        manager.sendTextMessage(st.nextToken(), null, getString(R.string.signal_test_message), null, null);

    }
  }
}

代码示例来源:origin: guardianproject/haven

SmsManager manager = SmsManager.getDefault();

代码示例来源:origin: 18Gray/CommonUtils

/**
 * 调用系统短信接口,后台发送短信
 * @param destinationAddress
 * @param text
 * @param sentIntent
 * @param deliveryIntent
 */
public static void sendSMSBackground(String destinationAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
{
  SmsManager smsManager = SmsManager.getDefault();
  smsManager.sendTextMessage(destinationAddress, null, text, sentIntent, deliveryIntent);
}

代码示例来源:origin: CesarValiente/PermissionsSample

public void sendSMS(String phoneNumber, String message) {
    PendingIntent sentPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(SMS_SENT), 0);
    PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast(context, 0, new Intent(SMS_DELIVERED), 0);

    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(phoneNumber, null, message, sentPendingIntent,
        deliveredPendingIntent);
  }
}

代码示例来源:origin: piotrpolak/android-http-server

public void sendMessage(final String phoneNumber, final String message) {
  Intent intent = new Intent(context, context.getClass());
  PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 0);
  SmsManager smsManager = SmsManager.getDefault();
  smsManager.sendTextMessage(phoneNumber, null, message, pi, null);
}

代码示例来源:origin: THEONE10211024/ApiDemos

/**
   * Get the config of whether Content-Disposition header is supported
   * for default carrier using new SmsManager API
   *
   * @return true if supported, false otherwise
   */
  public static boolean shouldParseContentDisposition() {
    return SmsManager
        .getDefault()
        .getCarrierConfigValues()
        .getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION, true);
  }
}

代码示例来源:origin: nglauber/dominando_android2

public void enviarSmsClick(View v) {
  PendingIntent pitEnviado = PendingIntent.getBroadcast(
      this, 0, new Intent(ACAO_ENVIADO), 0);
  PendingIntent pitEntregue = PendingIntent.getBroadcast(
      this, 0, new Intent(ACAO_ENTREGUE), 0);
  SmsManager smsManager = SmsManager.getDefault();
  smsManager.sendTextMessage(
      mEdtNumero.getText().toString(),
      null,
      mEdtMensagem.getText().toString(),
      pitEnviado,
      pitEntregue);
}

代码示例来源:origin: qiubiteme/android_api_demos

/**
   * Get the config of whether Content-Disposition header is supported
   * for default carrier using new SmsManager API
   *
   * @return true if supported, false otherwise
   */
  public static boolean shouldParseContentDisposition() {
    return SmsManager
        .getDefault()
        .getCarrierConfigValues()
        .getBoolean(SmsManager.MMS_CONFIG_SUPPORT_MMS_CONTENT_DISPOSITION, true);
  }
}

代码示例来源:origin: roxma/SMS-Forward

public void sendSMS(View v)
{
  EditText editText = (EditText) findViewById(R.id.edit_phone_number);
  String number = editText.getText().toString();
  SharedPreferences.Editor editor = getSharedPreferences("data", Context.MODE_PRIVATE).edit();
  editor.putString("number", number);
  editor.commit();
  String message  = "This is a test message to " + number;
  Log.i("sms","message send:" + message);
  SmsManager.getDefault().sendTextMessage(number,null,message,null,null);
}

代码示例来源:origin: hussien89aa/FindMyPhoneBuzzle

public  void sendm(String senderNum ){
  Location lastloc=SettingSaved.getLocation(context);
  SmsManager smsManagersend = SmsManager.getDefault();
  smsManagersend.sendTextMessage(senderNum, null, "%Here is my phone %https://www.google.com/maps/@" + lastloc.getLatitude() + "," + lastloc.getLongitude() + ",15z/data=!4m2!3m1!1s0x0000000000000000:0x08cdd5fc704c0eb2", null, null);
}

代码示例来源:origin: HaoFeiWang/MessageRelayer

/**
   * 发送短信至目标手机号
   * @param dataManager
   * @param content      短信内容
   */
  public static void relaySms(NativeDataManager dataManager, String content) {
    String objectMobile = dataManager.getObjectMobile();
    android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
    smsManager.sendTextMessage(objectMobile, null, content, null, null);
  }
}

代码示例来源:origin: jenly1314/Base

/**
 * 发短信
 *
 * @param phoneNumber
 * @param msg
 *
 */
public static void sendSMS(String phoneNumber, String msg) {
  SmsManager sm = SmsManager.getDefault();
  List<String> msgs = sm.divideMessage(msg);
  for (String text : msgs) {
    sm.sendTextMessage(phoneNumber, null, text, null, null);
  }
}

代码示例来源:origin: hussien89aa/FindMyPhoneBuzzle

public void MyLOC(){

    try {
      Location lastloc=SettingSaved.getLocation(this);

      SmsManager smsManagersend = SmsManager.getDefault();
      if(SettingSaved.UserPhoneNumber.length()>4) {  // in case we have saved list phone
        for (Map.Entry m : SettingSaved.WhoFindMeIN.entrySet())
          smsManagersend.sendTextMessage(m.getKey().toString(), null,"%"+ getResources().getString(R.string.HelpMSG) + "%https://www.google.com/maps/@"+lastloc.getLatitude()+","+ lastloc.getLongitude()+",15z/data=!4m2!3m1!1s0x0000000000000000:0x08cdd5fc704c0eb2", null, null);
  MessageSend( getResources().getString(R.string.MsgSent) );
      }
    } catch(Exception e)   {
      MessageSend( getResources().getString(R.string.MsgFail)  );  }
  }
public void MessageSend(String msg){

代码示例来源:origin: renyuneyun/Easer

@Override
  public boolean load(@ValidData @NonNull SmsOperationData data) {
    String destination = data.destination;
    String content = Utils.format(data.content);
    SmsManager smsManager = SmsManager.getDefault();
    if (smsManager == null)
      return false;
    smsManager.sendTextMessage(destination, null, content, null, null);
    return true;
  }
}

代码示例来源:origin: PandaQAQ/MvpDemo

/**
   * 直接调用短信接口发短信
   *
   * @param phoneNumber
   * @param message
   */
  private void sendSMS(String phoneNumber, String message) {
    //获取短信管理器
    android.telephony.SmsManager smsManager = android.telephony.SmsManager.getDefault();
    //拆分短信内容(手机短信长度限制)
    List<String> divideContents = smsManager.divideMessage(message);
    for (String text : divideContents) {
      smsManager.sendTextMessage(phoneNumber, null, text, null, null);
    }
  }
}

代码示例来源:origin: RomascuAndrei/BTNotifierAndroid

@Override
void manageEvent(NotificationListenerService context, JsonReader reader) throws IOException {
  String[] values = parse(reader);
  String number = values[0];
  String message = values[1];
  SmsManager smsManager = SmsManager.getDefault();
  ArrayList<String> messages = smsManager.divideMessage(message);
  smsManager.sendMultipartTextMessage(number, null, messages, null, null);
}

代码示例来源:origin: AmazingUU/Android-VoiceAssistant

private void sendMessage(String content) {
  if (msg_number==null){
    return;
  }
  SmsManager manager = SmsManager.getDefault();
  ArrayList<String> list = manager.divideMessage(content);  //因为一条短信有字数限制,因此要将长短信拆分
  for(String text:list){
    manager.sendTextMessage(msg_number, null, text, null, null);
  }
  refresh("已经发送"+"\""+content+"\""+"给"+msg_name,RECEIVER);
  speak(listData.getContent());
}

相关文章