use of android.telephony.SmsManager in project AndroidUtilCode by Blankj.
the class PhoneUtils method sendSmsSilent.
/**
* 发送短信
* <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);
}
}
use of android.telephony.SmsManager in project PermissionsSample by CesarValiente.
the class SMSActionImpl method sendSMS.
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);
}
use of android.telephony.SmsManager in project Ushahidi_Android by ushahidi.
the class OpenGeoSMSSender method sendReport.
public boolean sendReport(String address, String url, ReportEntity report) {
String smsMsg = createReport(url, report);
SmsManager smsManager = SmsManager.getDefault();
ArrayList<String> msgs = smsManager.divideMessage(smsMsg);
ArrayList<PendingIntent> pendingIntents = new ArrayList<PendingIntent>();
String action = OpenGeoSMSSender.class.getCanonicalName() + UUID.randomUUID().toString();
Intent intent = new Intent(action);
for (int i = 0; i < msgs.size(); i++) {
pendingIntents.add(PendingIntent.getBroadcast(mContext, 0, intent, 0));
}
Receiver r = new Receiver();
mContext.registerReceiver(r, new IntentFilter(action));
smsManager.sendMultipartTextMessage(address, null, msgs, pendingIntents, null);
return r.waitForResult(pendingIntents);
}
use of android.telephony.SmsManager in project kdeconnect-android by KDE.
the class TelepathyPlugin method onPackageReceived.
@Override
public boolean onPackageReceived(NetworkPackage np) {
if (!np.getType().equals(PACKAGE_TYPE_SMS_REQUEST)) {
return false;
}
if (np.getBoolean("sendSms")) {
String phoneNo = np.getString("phoneNumber");
String sms = np.getString("messageBody");
try {
int permissionCheck = ContextCompat.checkSelfPermission(context, Manifest.permission.SEND_SMS);
if (permissionCheck == PackageManager.PERMISSION_GRANTED) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, sms, null, null);
Log.d("TelepathyPlugin", "SMS sent");
} else if (permissionCheck == PackageManager.PERMISSION_DENIED) {
// TODO Request Permission SEND_SMS
}
//TODO: Notify other end
} catch (Exception e) {
//TODO: Notify other end
Log.e("TelepathyPlugin", e.getMessage());
e.printStackTrace();
}
}
return true;
}
Aggregations