Java Code Examples for android.telephony.SmsManager#RESULT_ERROR_NO_SERVICE
The following examples show how to use
android.telephony.SmsManager#RESULT_ERROR_NO_SERVICE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmsStateChangeReceiver.java From flutter_sms with MIT License | 6 votes |
String sentResult(int resultCode) { switch (resultCode) { case Activity.RESULT_OK: return "Activity.RESULT_OK"; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: return "SmsManager.RESULT_ERROR_GENERIC_FAILURE"; case SmsManager.RESULT_ERROR_RADIO_OFF: return "SmsManager.RESULT_ERROR_RADIO_OFF"; case SmsManager.RESULT_ERROR_NULL_PDU: return "SmsManager.RESULT_ERROR_NULL_PDU"; case SmsManager.RESULT_ERROR_NO_SERVICE: return "SmsManager.RESULT_ERROR_NO_SERVICE"; default: return "Unknown error code"; } }
Example 2
Source File: SMSReceiver.java From PermissionsSample with Apache License 2.0 | 6 votes |
public static BroadcastReceiver getSMSSentReceiver() { // For when the SMS has been sent return new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(context, R.string.sms_sent, Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(context, R.string.sms_generic_failure, Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Toast.makeText(context, R.string.sms_no_service, Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(context, R.string.sms_no_pdu, Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(context, R.string.sms_radio_turned_off, Toast.LENGTH_SHORT).show(); break; } } }; }
Example 3
Source File: ThreadSendSMS.java From GPS2SMS with GNU General Public License v3.0 | 6 votes |
@Override public void onReceive(Context context, Intent arg1) { setSendRecFired(send_receiver_fired + 1); switch (getResultCode()) { case Activity.RESULT_OK: setResSend(context.getString(R.string.info_sms_sent)); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: setResSend(context.getString(R.string.info_sms_generic)); break; case SmsManager.RESULT_ERROR_NO_SERVICE: setResSend(context.getString(R.string.info_sms_noservice)); break; case SmsManager.RESULT_ERROR_NULL_PDU: setResSend(context.getString(R.string.info_sms_nullpdu)); break; case SmsManager.RESULT_ERROR_RADIO_OFF: setResSend(context.getString(R.string.info_sms_radioof)); break; } }
Example 4
Source File: SmsSnippet.java From mobly-bundled-snippets with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (SMS_SENT_ACTION.equals(action)) { SnippetEvent event = new SnippetEvent(mCallbackId, SMS_SENT_EVENT_NAME); switch (getResultCode()) { case Activity.RESULT_OK: if (mExpectedMessageCount == 1) { event.getData().putBoolean("sent", true); mEventCache.postEvent(event); mContext.unregisterReceiver(this); } if (mExpectedMessageCount > 0) { mExpectedMessageCount--; } break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: case SmsManager.RESULT_ERROR_NO_SERVICE: case SmsManager.RESULT_ERROR_NULL_PDU: case SmsManager.RESULT_ERROR_RADIO_OFF: event.getData().putBoolean("sent", false); event.getData().putInt("error_code", getResultCode()); mEventCache.postEvent(event); mContext.unregisterReceiver(this); break; default: event.getData().putBoolean("sent", false); event.getData().putInt("error_code", -1 /* Unknown */); mEventCache.postEvent(event); mContext.unregisterReceiver(this); break; } } }
Example 5
Source File: Texting.java From appinventor-extensions with Apache License 2.0 | 5 votes |
/** * Callback method to handle the result of attempting to send a message. * Each message is assigned a Broadcast receiver that is notified by * the phone's radio regarding the status of the sent message. The * receivers call this method. (See transmitMessage() method below.) * * @param context * The context in which the calling BroadcastReceiver is running. * @param receiver * Currently unused. Intended as a special BroadcastReceiver to * send results to. (For instance, if another plugin wanted to do * its own handling.) * @param resultCode, the code sent back by the phone's Radio * @param seq, the message's sequence number * @param smsMsg, the message being processed */ private synchronized void handleSentMessage(Context context, BroadcastReceiver receiver, int resultCode, String smsMsg) { switch (resultCode) { case Activity.RESULT_OK: Log.i(TAG, "Received OK, msg:" + smsMsg); Toast.makeText(activity, "Message sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Log.e(TAG, "Received generic failure, msg:" + smsMsg); Toast.makeText(activity, "Generic failure: message not sent", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NO_SERVICE: Log.e(TAG, "Received no service error, msg:" + smsMsg); Toast.makeText(activity, "No Sms service available. Message not sent.", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Log.e(TAG, "Received null PDU error, msg:" + smsMsg); Toast.makeText(activity, "Received null PDU error. Message not sent.", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Log.e(TAG, "Received radio off error, msg:" + smsMsg); Toast.makeText(activity, "Could not send SMS message: radio off.", Toast.LENGTH_LONG).show(); break; } }
Example 6
Source File: SmsSentJob.java From Silence with GNU General Public License v3.0 | 5 votes |
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, record.isSecure()); if (record != null && record.isEndSession()) { Log.w(TAG, "Ending session..."); SessionStore sessionStore = new SilenceSessionStore(context, masterSecret, record.getSubscriptionId()); sessionStore.deleteAllSessions(record.getIndividualRecipient().getNumber()); SecurityEvent.broadcastSecurityUpdateEvent(context, record.getThreadId()); } 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); } }
Example 7
Source File: SMSSendResultBroadcastReceiver.java From BlackList with Apache License 2.0 | 4 votes |
private void onSMSSent(Context context, Intent intent, int result) { boolean failed = true; int stringId = R.string.Unknown_error; switch (result) { case Activity.RESULT_OK: stringId = R.string.SMS_is_sent; failed = false; break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: stringId = R.string.Generic_failure; break; case SmsManager.RESULT_ERROR_NO_SERVICE: stringId = R.string.No_service; break; case SmsManager.RESULT_ERROR_NULL_PDU: stringId = R.string.Null_PDU; break; case SmsManager.RESULT_ERROR_RADIO_OFF: stringId = R.string.Radio_off; break; } // get SMS parameters String phoneNumber = intent.getStringExtra(PHONE_NUMBER); if (phoneNumber != null) { int messagePartId = intent.getIntExtra(MESSAGE_PART_ID, 0); int messageParts = intent.getIntExtra(MESSAGE_PARTS, 0); long messageId = intent.getLongExtra(MESSAGE_ID, 0); boolean delivery = intent.getBooleanExtra(DELIVERY, false); // if the last part of the message was sent if (messageParts > 0 && messagePartId == messageParts) { // notify the user about the message sending String message = phoneNumber + "\n" + context.getString(stringId); Utils.showToast(context, message, Toast.LENGTH_SHORT); if (messageId >= 0) { // update written message as sent ContactsAccessHelper db = ContactsAccessHelper.getInstance(context); db.updateSMSMessageOnSent(context, messageId, delivery, failed); } // send internal event message InternalEventBroadcast.sendSMSWasWritten(context, phoneNumber); } } }
Example 8
Source File: SmsSentService.java From SmsScheduler with GNU General Public License v2.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { super.onHandleIntent(intent); if (timestampCreated == 0) { return; } Log.i(getClass().getName(), "Notifying that sms " + timestampCreated + " is sent"); SmsModel sms = DbHelper.getDbHelper(this).get(timestampCreated); String errorId = ""; String errorString = ""; String title = getString(R.string.notification_title_failure); String message = ""; sms.setStatus(SmsModel.STATUS_FAILED); switch (intent.getIntExtra(SmsSentReceiver.RESULT_CODE, 0)) { case Activity.RESULT_OK: title = getString(R.string.notification_title_success); message = getString(R.string.notification_message_success, sms.getRecipientName()); sms.setStatus(SmsModel.STATUS_SENT); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: errorId = SmsModel.ERROR_GENERIC; errorString = getString(R.string.error_generic); break; case SmsManager.RESULT_ERROR_NO_SERVICE: errorId = SmsModel.ERROR_NO_SERVICE; errorString = getString(R.string.error_no_service); break; case SmsManager.RESULT_ERROR_NULL_PDU: errorId = SmsModel.ERROR_NULL_PDU; errorString = getString(R.string.error_null_pdu); break; case SmsManager.RESULT_ERROR_RADIO_OFF: errorId = SmsModel.ERROR_RADIO_OFF; errorString = getString(R.string.error_radio_off); break; default: errorId = SmsModel.ERROR_UNKNOWN; errorString = getString(R.string.error_unknown); break; } if (errorId.length() > 0) { sms.setResult(errorId); message = getString(R.string.notification_message_failure, sms.getRecipientName(), errorString); } DbHelper.getDbHelper(this).save(sms); notify(this, title, message, sms.getId()); WakefulBroadcastReceiver.completeWakefulIntent(intent); }
Example 9
Source File: SmsSentService.java From RememBirthday with GNU General Public License v3.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { super.onHandleIntent(intent); if (timestampCreated == 0) { return; } Log.i(getClass().getName(), "Notifying that sms " + timestampCreated + " is sent"); AutoSms sms = AutoSmsDbHelper.getDbHelper(this).getAutoSmsById(timestampCreated); String errorId = ""; String errorString = ""; String title = "";//getString(R.string.notification_title_failure); String message = ""; sms.setStatus(AutoSms.Status.FAILED); switch (intent.getIntExtra(SmsSentReceiver.RESULT_CODE, 0)) { case Activity.RESULT_OK: //title = getString(R.string.notification_title_success); //message = getString(R.string.notification_message_success, sms.getRecipientLookup()); sms.setStatus(AutoSms.Status.SEND); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: errorId = AutoSms.ERROR_GENERIC; //errorString = getString(R.string.error_generic); break; case SmsManager.RESULT_ERROR_NO_SERVICE: errorId = AutoSms.ERROR_NO_SERVICE; //errorString = getString(R.string.error_no_service); break; case SmsManager.RESULT_ERROR_NULL_PDU: errorId = AutoSms.ERROR_NULL_PDU; //errorString = getString(R.string.error_null_pdu); break; case SmsManager.RESULT_ERROR_RADIO_OFF: errorId = AutoSms.ERROR_RADIO_OFF; //errorString = getString(R.string.error_radio_off); break; default: errorId = AutoSms.ERROR_UNKNOWN; //errorString = getString(R.string.error_unknown); break; } if (errorId.length() > 0) { sms.setResult(errorId); //message = getString(R.string.notification_message_failure, sms.getRecipientLookup(), errorString); } AutoSmsDbHelper.getDbHelper(this).insert(sms); notify(this, title, message, sms.getDateCreated().getTime()); WakefulBroadcastReceiver.completeWakefulIntent(intent); }
Example 10
Source File: Sms.java From cordova-sms-plugin with MIT License | 4 votes |
private void send(final CallbackContext callbackContext, String phoneNumber, String message) { SmsManager manager = SmsManager.getDefault(); final ArrayList<String> parts = manager.divideMessage(message); // by creating this broadcast receiver we can check whether or not the SMS was sent final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { boolean anyError = false; //use to detect if one of the parts failed int partsCount = parts.size(); //number of parts to send @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case SmsManager.STATUS_ON_ICC_SENT: case Activity.RESULT_OK: break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: case SmsManager.RESULT_ERROR_NO_SERVICE: case SmsManager.RESULT_ERROR_NULL_PDU: case SmsManager.RESULT_ERROR_RADIO_OFF: anyError = true; break; } // trigger the callback only when all the parts have been sent partsCount--; if (partsCount == 0) { if (anyError) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR)); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK)); } cordova.getActivity().unregisterReceiver(this); } } }; // randomize the intent filter action to avoid using the same receiver String intentFilterAction = INTENT_FILTER_SMS_SENT + java.util.UUID.randomUUID().toString(); this.cordova.getActivity().registerReceiver(broadcastReceiver, new IntentFilter(intentFilterAction)); PendingIntent sentIntent = PendingIntent.getBroadcast(this.cordova.getActivity(), 0, new Intent(intentFilterAction), 0); // depending on the number of parts we send a text message or multi parts if (parts.size() > 1) { ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>(); for (int i = 0; i < parts.size(); i++) { sentIntents.add(sentIntent); } manager.sendMultipartTextMessage(phoneNumber, null, parts, sentIntents, null); } else { manager.sendTextMessage(phoneNumber, null, message, sentIntent, null); } }