Java Code Examples for android.telephony.SmsManager#getSmsManagerForSubscriptionId()
The following examples show how to use
android.telephony.SmsManager#getSmsManagerForSubscriptionId() .
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: public_func.java From dingtalk-sms with BSD 3-Clause "New" or "Revised" License | 7 votes |
static void send_sms(Context context, String send_to, String content, int sub_id) { android.telephony.SmsManager sms_manager; String sim_card = "1"; if (sub_id == -1) { sms_manager = SmsManager.getDefault(); } else { sms_manager = SmsManager.getSmsManagerForSubscriptionId(sub_id); sim_card = "2"; } ArrayList<String> divideContents = sms_manager.divideMessage(content); ArrayList<PendingIntent> send_receiver_list = new ArrayList<>(); IntentFilter filter = new IntentFilter("send_sms"); BroadcastReceiver receiver = new sms_send_receiver(); context.getApplicationContext().registerReceiver(receiver, filter); Intent sent_intent = new Intent("send_sms"); sent_intent.putExtra("sim_card", sim_card); sent_intent.putExtra("send_to", send_to); sent_intent.putExtra("content", content); PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, sent_intent, PendingIntent.FLAG_CANCEL_CURRENT); send_receiver_list.add(sentIntent); sms_manager.sendMultipartTextMessage(send_to, null, divideContents, send_receiver_list, null); }
Example 2
Source File: public_func.java From telegram-sms with BSD 3-Clause "New" or "Revised" License | 6 votes |
static void send_fallback_sms(Context context, String content, int sub_id) { final String TAG = "send_fallback_sms"; if (androidx.core.content.PermissionChecker.checkSelfPermission(context, Manifest.permission.SEND_SMS) != PermissionChecker.PERMISSION_GRANTED) { Log.d(TAG, "No permission."); return; } SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE); String trust_number = sharedPreferences.getString("trusted_phone_number", null); if (trust_number == null) { Log.i(TAG, "The trusted number is empty."); return; } if (!sharedPreferences.getBoolean("fallback_sms", false)) { Log.i(TAG, "Did not open the SMS to fall back."); return; } android.telephony.SmsManager sms_manager; if (sub_id == -1) { sms_manager = SmsManager.getDefault(); } else { sms_manager = SmsManager.getSmsManagerForSubscriptionId(sub_id); } ArrayList<String> divideContents = sms_manager.divideMessage(content); sms_manager.sendMultipartTextMessage(trust_number, null, divideContents, null, null); }
Example 3
Source File: public_func.java From dingtalk-sms with BSD 3-Clause "New" or "Revised" License | 5 votes |
static void send_fallback_sms(String send_to, String content, int sub_id) { android.telephony.SmsManager sms_manager; if (sub_id == -1) { sms_manager = SmsManager.getDefault(); } else { sms_manager = SmsManager.getSmsManagerForSubscriptionId(sub_id); } ArrayList<String> divideContents = sms_manager.divideMessage(content); sms_manager.sendMultipartTextMessage(send_to, null, divideContents, null, null); }
Example 4
Source File: SmsSender.java From flutter_sms with MIT License | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) private void sendSmsMessage() { Intent sentIntent = new Intent("SMS_SENT"); sentIntent.putExtra("sentId", sentId); PendingIntent sentPendingIntent = PendingIntent.getBroadcast( registrar.context(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT ); Intent deliveredIntent = new Intent("SMS_DELIVERED"); deliveredIntent.putExtra("sentId", sentId); PendingIntent deliveredPendingIntent = PendingIntent.getBroadcast( registrar.context(), UUID.randomUUID().hashCode(), deliveredIntent, PendingIntent.FLAG_UPDATE_CURRENT ); SmsManager sms; if (this.subId == null) { sms = SmsManager.getDefault(); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { sms = SmsManager.getSmsManagerForSubscriptionId(this.subId); } else { result.error("#03", "this version of android does not support multicard SIM", null); return; } } sms.sendTextMessage(address, null, body, sentPendingIntent, deliveredPendingIntent); result.success(null); }
Example 5
Source File: MainActivity.java From Msgs with MIT License | 5 votes |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1) private void sendSms(final int which,String phone,String context) { SubscriptionInfo sInfo = null; final SubscriptionManager sManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); List<SubscriptionInfo> list = sManager.getActiveSubscriptionInfoList(); if (list.size() == 2) { // 双卡 sInfo = list.get(which); } else { // 单卡 sInfo = list.get(0); } if (sInfo != null) { int subId = sInfo.getSubscriptionId(); SmsManager manager = SmsManager.getSmsManagerForSubscriptionId(subId); if (!TextUtils.isEmpty(phone)) { ArrayList<String> messageList =manager.divideMessage(context); for(String text:messageList){ manager.sendTextMessage(phone, null, text, null, null); } Toast.makeText(this, "信息正在发送,请稍候", Toast.LENGTH_SHORT) .show(); } else { Toast.makeText(this, "无法正确的获取SIM卡信息,请稍候重试", Toast.LENGTH_SHORT).show(); } } }
Example 6
Source File: SMSSendHelper.java From BlackList with Apache License 2.0 | 5 votes |
private SmsManager getSmsManager(Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) { Integer subscriptionId = SubscriptionHelper.getCurrentSubscriptionId(context); if (subscriptionId != null) { return SmsManager.getSmsManagerForSubscriptionId(subscriptionId); } } return SmsManager.getDefault(); }
Example 7
Source File: SmsSenderService.java From SmsScheduler with GNU General Public License v2.0 | 5 votes |
private SmsManager getSmsManager(int subscriptionId) { SmsManager smsManager = SmsManager.getDefault(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { return smsManager; } SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); if (null == subscriptionManager) { return smsManager; } if (null == subscriptionManager.getActiveSubscriptionInfo(subscriptionId)) { return smsManager; } return SmsManager.getSmsManagerForSubscriptionId(subscriptionId); }
Example 8
Source File: SmsSenderService.java From RememBirthday with GNU General Public License v3.0 | 5 votes |
private SmsManager getSmsManager(int subscriptionId) { SmsManager smsManager = SmsManager.getDefault(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) { return smsManager; } SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); if (null == subscriptionManager) { return smsManager; } if (null == subscriptionManager.getActiveSubscriptionInfo(subscriptionId)) { return smsManager; } return SmsManager.getSmsManagerForSubscriptionId(subscriptionId); }
Example 9
Source File: SmsSendJob.java From Silence with GNU General Public License v3.0 | 5 votes |
private SmsManager getSmsManagerFor(int subscriptionId) { Log.w(TAG, "getSmsManagerFor(" + subscriptionId + ")"); if (Build.VERSION.SDK_INT >= 22 && subscriptionId != -1) { return SmsManager.getSmsManagerForSubscriptionId(subscriptionId); } else { return SmsManager.getDefault(); } }
Example 10
Source File: public_func.java From telegram-sms with BSD 3-Clause "New" or "Revised" License | 4 votes |
static void send_sms(Context context, String send_to, String content, int slot, int sub_id) { if (androidx.core.content.PermissionChecker.checkSelfPermission(context, Manifest.permission.SEND_SMS) != PermissionChecker.PERMISSION_GRANTED) { Log.d("send_sms", "No permission."); return; } if (!is_phone_number(send_to)) { write_log(context, "[" + send_to + "] is an illegal phone number"); return; } SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE); String bot_token = sharedPreferences.getString("bot_token", ""); String chat_id = sharedPreferences.getString("chat_id", ""); String request_uri = public_func.get_url(bot_token, "sendMessage"); message_json request_body = new message_json(); request_body.chat_id = chat_id; android.telephony.SmsManager sms_manager; if (sub_id == -1) { sms_manager = SmsManager.getDefault(); } else { sms_manager = SmsManager.getSmsManagerForSubscriptionId(sub_id); } String dual_sim = get_dual_sim_card_display(context, slot, sharedPreferences.getBoolean("display_dual_sim_display_name", false)); String send_content = "[" + dual_sim + context.getString(R.string.send_sms_head) + "]" + "\n" + context.getString(R.string.to) + send_to + "\n" + context.getString(R.string.content) + content; String message_id = "-1"; request_body.text = send_content + "\n" + context.getString(R.string.status) + context.getString(R.string.sending); String request_body_raw = new Gson().toJson(request_body); RequestBody body = RequestBody.create(request_body_raw, public_func.JSON); OkHttpClient okhttp_client = public_func.get_okhttp_obj(sharedPreferences.getBoolean("doh_switch", true), Paper.book().read("proxy_config", new proxy_config())); Request request = new Request.Builder().url(request_uri).method("POST", body).build(); Call call = okhttp_client.newCall(request); try { Response response = call.execute(); if (response.code() != 200 || response.body() == null) { throw new IOException(String.valueOf(response.code())); } message_id = get_message_id(Objects.requireNonNull(response.body()).string()); } catch (IOException e) { e.printStackTrace(); public_func.write_log(context, "failed to send message:" + e.getMessage()); } ArrayList<String> divideContents = sms_manager.divideMessage(content); ArrayList<PendingIntent> send_receiver_list = new ArrayList<>(); IntentFilter filter = new IntentFilter("send_sms"); BroadcastReceiver receiver = new sms_send_receiver(); context.getApplicationContext().registerReceiver(receiver, filter); Intent sent_intent = new Intent("send_sms"); sent_intent.putExtra("message_id", message_id); sent_intent.putExtra("message_text", send_content); sent_intent.putExtra("sub_id", sms_manager.getSubscriptionId()); PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, sent_intent, PendingIntent.FLAG_CANCEL_CURRENT); send_receiver_list.add(sentIntent); sms_manager.sendMultipartTextMessage(send_to, null, divideContents, send_receiver_list, null); }
Example 11
Source File: IncomingLollipopMmsConnection.java From Silence with GNU General Public License v3.0 | 4 votes |
@Override @TargetApi(VERSION_CODES.LOLLIPOP) public synchronized @Nullable RetrieveConf retrieve(@NonNull String contentLocation, byte[] transactionId, int subscriptionId) throws MmsException { beginTransaction(); try { MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext()); Log.w(TAG, "downloading multimedia from " + contentLocation + " to " + pointer.getUri()); SmsManager smsManager; if (VERSION.SDK_INT >= 22 && subscriptionId != -1) { smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId); } else { smsManager = SmsManager.getDefault(); } smsManager.downloadMultimediaMessage(getContext(), contentLocation, pointer.getUri(), null, getPendingIntent()); waitForResult(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Util.copy(pointer.getInputStream(), baos); pointer.close(); Log.w(TAG, baos.size() + "-byte response: ");// + Hex.dump(baos.toByteArray())); return (RetrieveConf) new PduParser(baos.toByteArray()).parse(); } catch (IOException | TimeoutException e) { Log.w(TAG, e); throw new MmsException(e); } finally { endTransaction(); } }
Example 12
Source File: OutgoingLollipopMmsConnection.java From Silence with GNU General Public License v3.0 | 4 votes |
@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(); } Bundle configOverrides = new Bundle(); configOverrides.putBoolean(SmsManager.MMS_CONFIG_GROUP_MMS_ENABLED, true); MmsConfig mmsConfig = MmsConfigManager.getMmsConfig(getContext(), subscriptionId); if (mmsConfig != null) { MmsConfig.Overridden overridden = new MmsConfig.Overridden(mmsConfig, new Bundle()); configOverrides.putString(SmsManager.MMS_CONFIG_HTTP_PARAMS, overridden.getHttpParams()); configOverrides.putInt(SmsManager.MMS_CONFIG_MAX_MESSAGE_SIZE, overridden.getMaxMessageSize()); } smsManager.sendMultimediaMessage(getContext(), pointer.getUri(), null, configOverrides, 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(); } }