Search in sources :

Example 6 with SmsManager

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);
    }
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) SmsManager(android.telephony.SmsManager)

Example 7 with SmsManager

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);
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) SmsManager(android.telephony.SmsManager)

Example 8 with SmsManager

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);
}
Also used : IntentFilter(android.content.IntentFilter) ArrayList(java.util.ArrayList) BroadcastReceiver(android.content.BroadcastReceiver) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) SmsManager(android.telephony.SmsManager)

Example 9 with SmsManager

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;
}
Also used : SmsManager(android.telephony.SmsManager)

Aggregations

SmsManager (android.telephony.SmsManager)9 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5 IOException (java.io.IOException)3 TargetApi (android.annotation.TargetApi)2 Nullable (android.support.annotation.Nullable)2 ArrayList (java.util.ArrayList)2 TimeoutException (java.util.concurrent.TimeoutException)2 MmsBodyProvider (org.thoughtcrime.securesms.providers.MmsBodyProvider)2 PduParser (ws.com.google.android.mms.pdu.PduParser)2 Activity (android.app.Activity)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentValues (android.content.ContentValues)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 Cursor (android.database.Cursor)1 Uri (android.net.Uri)1 MmsException (com.google.android.mms.MmsException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1