本文整理汇总了Java中android.telephony.SmsManager类的典型用法代码示例。如果您正苦于以下问题:Java SmsManager类的具体用法?Java SmsManager怎么用?Java SmsManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SmsManager类属于android.telephony包,在下文中一共展示了SmsManager类的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: 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);
}
示例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();
}
}
示例4: setupViews
import android.telephony.SmsManager; //导入依赖的package包/类
private void setupViews(){
etName = (EditText) findViewById(R.id.etLoginName);
etPhoneNumber = (EditText) findViewById(R.id.etLoginPhoneNumber);
etPhoneNumber.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
bLogin = (Button) findViewById(R.id.bLogin);
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Create a new user and signup
String verifyCode = Utils.generateRandomCode();
// Send SMS with verify code starts here
SmsManager smsManager = SmsManager.getDefault();
String smsMessage = verifyCode + " " + Constants.VERIFICATION_SMS_TEXT;
smsManager.sendTextMessage(etPhoneNumber.getText().toString(), null, smsMessage, null, null);
// Send SMS with verify code ends here
Intent intent = new Intent(LoginActivity.this, PhoneNoVerificationActivity.class);
intent.putExtra("etName", etName.getText().toString());
intent.putExtra("etPhoneNumber", etPhoneNumber.getText().toString());
intent.putExtra("verifyCode", verifyCode);
Log.v("verifyCode", "verifyCode-=============================== " + verifyCode);
startActivityForResult(intent, 30);
}
});
}
示例5: send
import android.telephony.SmsManager; //导入依赖的package包/类
@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
public @Nullable synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId)
throws UndeliverableMessageException
{
beginTransaction();
try {
MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
Util.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());
SmsManager smsManager;
if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
} else {
smsManager = SmsManager.getDefault();
}
smsManager.sendMultimediaMessage(getContext(),
pointer.getUri(),
null,
null,
getPendingIntent());
waitForResult();
Log.w(TAG, "MMS broadcast received and processed.");
pointer.close();
if (response == null) {
throw new UndeliverableMessageException("Null response.");
}
return (SendConf) new PduParser(response).parse();
} catch (IOException | TimeoutException e) {
throw new UndeliverableMessageException(e);
} finally {
endTransaction();
}
}
示例6: handleSentResult
import android.telephony.SmsManager; //导入依赖的package包/类
private void handleSentResult(MasterSecret masterSecret, long messageId, int result) {
try {
EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
SmsMessageRecord record = database.getMessage(masterSecret, messageId);
switch (result) {
case Activity.RESULT_OK:
database.markAsSent(messageId, false);
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
case SmsManager.RESULT_ERROR_RADIO_OFF:
Log.w(TAG, "Service connectivity problem, requeuing...");
ApplicationContext.getInstance(context)
.getJobManager()
.add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
break;
default:
database.markAsSentFailed(messageId);
MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
}
} catch (NoSuchMessageException e) {
Log.w(TAG, e);
}
}
示例7: 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();
}
}
示例8: onCreate
import android.telephony.SmsManager; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(getIntent().getExtras().getString("d1"), null, getIntent().getExtras().getString("d2"), null, null);
}
});
TextView t = (TextView) findViewById(R.id.textView1);
TextView t2 = (TextView) findViewById(R.id.textView2);
t.setText(getIntent().getExtras().getString("s1"));
t2.setText(getIntent().getExtras().getString("s2"));
}
示例9: onReceive
import android.telephony.SmsManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS enviado", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Falha geral", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "Sem serviço", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off", Toast.LENGTH_SHORT).show();
break;
}
unregisterReceiver(this);
}
示例10: 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);
}
}
示例11: 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 !
}
}
示例12: 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();
}
}
}
示例13: 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);
}
}
示例14: 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";
}
示例15: 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);
}