public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
if (Build.VERSION.SDK_INT < 22) {
return new LinkedList<>();
}
List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
return new LinkedList<>();
}
List<SubscriptionInfoCompat> compatList = new LinkedList<>();
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
subscriptionInfo.getDisplayName()));
}
return compatList;
}
java类android.telephony.SubscriptionInfo的实例源码
SubscriptionManagerCompat.java 文件源码
项目:PeSanKita-android
阅读 21
收藏 0
点赞 0
评论 0
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 25
收藏 0
点赞 0
评论 0
private boolean setDefaultSubscription(final SubType subType, final SubscriptionInfo subInfo) {
if (subInfo == null)
return false;
try {
if (subType == SubType.SMS) {
XposedHelpers.callMethod(mSubMgr, "setDefaultSmsSubId",
subInfo.getSubscriptionId());
} else if (subType == SubType.DATA) {
XposedHelpers.callMethod(mSubMgr, "setDefaultDataSubId",
subInfo.getSubscriptionId());
}
return true;
} catch (Throwable t) {
XposedBridge.log(t);
return false;
}
}
SimService.java 文件源码
项目:NotifyTools
阅读 18
收藏 0
点赞 0
评论 0
@Override
protected void onHandleIntent(Intent intent) {
log.d("onHandleIntent");
//SubscriptionManager 该类主要包含了所有sim卡的信息
SubscriptionManager mSubscriptionManager = SubscriptionManager.from(this);
int simcnt = mSubscriptionManager.getActiveSubscriptionInfoCount();
List<SubscriptionInfo> lstSim = mSubscriptionManager.getActiveSubscriptionInfoList();
for (int i = 0; i < lstSim.size(); i++) {
SubscriptionInfo si = lstSim.get(i);
if (si != null)
log.d(si.toString());
}
TelecomManager telecomManager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
List<PhoneAccountHandle> lstPA=telecomManager.getCallCapablePhoneAccounts();
int accoutSum =lstPA.size();
for(int i=0;i<accoutSum;i++)
log.d("accountSum: " + accoutSum +lstPA.get(i) );
}
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 24
收藏 0
点赞 0
评论 0
public void changeDefaultSub(final SubType subType, final int simSlot, final boolean showToast) {
boolean result;
SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfoForSimSlotIndex(simSlot);
if (subType == SubType.VOICE) {
if (si == null && (simSlot == 0 || simSlot == 1)) {
result = false;
} else {
result = setDefaultVoiceSubscription(si);
}
} else {
result = setDefaultSubscription(subType, si);
}
if (showToast || !result) {
final String msg = result ? getChangeOkMsg(subType, getSubDisplayName(si)) :
getChangeFailedMsg(subType);
Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
}
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 26
收藏 0
点赞 0
评论 0
private List<IIconListAdapterItem> getSubItemList(final SubType subType) {
List<IIconListAdapterItem> list = new ArrayList<>();
if (subType == SubType.VOICE) {
list.add(new SubListItem(null));
final TelecomManager telecomManager =
(TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
final TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final Iterator<PhoneAccountHandle> phoneAccounts =
telecomManager.getCallCapablePhoneAccounts().listIterator();
while (phoneAccounts.hasNext()) {
final PhoneAccount phoneAccount =
telecomManager.getPhoneAccount(phoneAccounts.next());
int subId = getSubIdForPhoneAccount(telephonyManager, phoneAccount);
if (subId != -1) {
list.add(new SubListItem(mSubMgr.getActiveSubscriptionInfo(subId)));
}
}
} else {
for (SubscriptionInfo si : mSubMgr.getActiveSubscriptionInfoList())
if (si != null)
list.add(new SubListItem(si));
}
return list;
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 24
收藏 0
点赞 0
评论 0
private PhoneAccountHandle subscriptionToPhoneAccountHandle(final SubscriptionInfo subInfo) {
if (subInfo == null)
return null;
final TelecomManager telecomManager =
(TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
final TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
final Iterator<PhoneAccountHandle> phoneAccounts =
telecomManager.getCallCapablePhoneAccounts().listIterator();
while (phoneAccounts.hasNext()) {
final PhoneAccountHandle phoneAccountHandle = phoneAccounts.next();
final PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle);
if (subInfo.getSubscriptionId() == getSubIdForPhoneAccount(telephonyManager, phoneAccount)) {
return phoneAccountHandle;
}
}
return null;
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 22
收藏 0
点赞 0
评论 0
private int getDefaultVoiceSubscriptionSimSlot() {
try {
final TelecomManager telecomManager =
(TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
final TelephonyManager telephonyManager =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
PhoneAccountHandle pah = (PhoneAccountHandle) XposedHelpers.callMethod(telecomManager,
"getUserSelectedOutgoingPhoneAccount");
if (pah != null) {
PhoneAccount pa = telecomManager.getPhoneAccount(pah);
int subId = getSubIdForPhoneAccount(telephonyManager, pa);
SubscriptionInfo si = mSubMgr.getActiveSubscriptionInfo(subId);
if (si != null) {
return si.getSimSlotIndex();
}
}
return -1;
} catch (Throwable t) {
XposedBridge.log(t);
return -1;
}
}
SubscriptionManagerCompat.java 文件源码
项目:Cable-Android
阅读 19
收藏 0
点赞 0
评论 0
public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
if (Build.VERSION.SDK_INT < 22) {
return new LinkedList<>();
}
List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
return new LinkedList<>();
}
List<SubscriptionInfoCompat> compatList = new LinkedList<>();
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
subscriptionInfo.getDisplayName(),
subscriptionInfo.getMcc(),
subscriptionInfo.getMnc()));
}
return compatList;
}
SubscriptionManagerCompat.java 文件源码
项目:Silence
阅读 19
收藏 0
点赞 0
评论 0
public @NonNull List<SubscriptionInfoCompat> getActiveSubscriptionInfoList() {
if (Build.VERSION.SDK_INT < 22) {
return new LinkedList<>();
}
List<SubscriptionInfo> subscriptionInfos = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if (subscriptionInfos == null || subscriptionInfos.isEmpty()) {
return new LinkedList<>();
}
List<SubscriptionInfoCompat> compatList = new LinkedList<>();
for (SubscriptionInfo subscriptionInfo : subscriptionInfos) {
compatList.add(new SubscriptionInfoCompat(subscriptionInfo.getSubscriptionId(),
subscriptionInfo.getDisplayName()));
}
return compatList;
}
SettingsFragment.java 文件源码
项目:sms-ticket
阅读 54
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private void fillDualSimList(PreferenceScreen preferenceScreen) {
PreferenceCategory category = (PreferenceCategory) preferenceScreen.findPreference("sms_category");
ListPreference preference = (ListPreference) category.findPreference(Preferences.DUALSIM_SIM);
List<String> simIds = new ArrayList<>();
List<String> simNames = new ArrayList<>();
simIds.add(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
simNames.add(getString(R.string.sim_default));
SubscriptionManager subscriptionManager = SubscriptionManager.from(getActivity());
for (SubscriptionInfo subscriptionInfo : subscriptionManager.getActiveSubscriptionInfoList()) {
simIds.add(String.valueOf(subscriptionInfo.getSubscriptionId()));
simNames.add(getString(R.string.sim_name, subscriptionInfo.getSimSlotIndex() + 1, subscriptionInfo
.getDisplayName()));
}
preference.setEntries(simNames.toArray(new String[simNames.size()]));
preference.setEntryValues(simIds.toArray(new String[simIds.size()]));
preference.setDefaultValue(String.valueOf(Preferences.VALUE_DEFAULT_SIM));
preference.setSummary(preference.getEntry());
}
SubscriptionManagerCompat.java 文件源码
项目:PeSanKita-android
阅读 19
收藏 0
点赞 0
评论 0
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
if (Build.VERSION.SDK_INT < 22) {
return Optional.absent();
}
SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);
if (subscriptionInfo != null) {
return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName()));
} else {
return Optional.absent();
}
}
MainActivity.java 文件源码
项目:Msgs
阅读 18
收藏 0
点赞 0
评论 0
@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();
}
}
}
SubscriptionInfoHelper.java 文件源码
项目:open-rmbt
阅读 29
收藏 0
点赞 0
评论 0
/**
* Get information about the SIM that is currently used for data
* @return info or NULL if there is no active sim or the active sim cannot be detected
*/
public ActiveDataSubscriptionInfo getActiveDataSubscriptionInfo() {
SubscriptionInfo activeSubscription;
ActiveDataSubscriptionInfo info = new ActiveDataSubscriptionInfo();
if (subscriptionManager.getActiveSubscriptionInfoCount() > 1) {
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
int dataSubscriptionId = subscriptionManager.getDefaultDataSubscriptionId();
activeSubscription = subscriptionManager.getActiveSubscriptionInfo(dataSubscriptionId);
}
else {
activeSubscription = null;
}
}
else if (subscriptionManager.getActiveSubscriptionInfoCount() == 1) {
activeSubscription = subscriptionManager.getActiveSubscriptionInfoList().get(0);
}
else {
activeSubscription = null;
}
if (activeSubscription != null) {
//fill info from this
info.setCountry(activeSubscription.getCountryIso());
String simOperator = activeSubscription.getMcc() + "-" + String.format("%02d", activeSubscription.getMnc());
info.setSimOperator(String.valueOf(simOperator));
info.setSimOperatorName(activeSubscription.getCarrierName().toString());
info.setDisplayName(activeSubscription.getDisplayName().toString());
info.setSimCount(subscriptionManager.getActiveSubscriptionInfoCount());
return info;
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 27
收藏 0
点赞 0
评论 0
@Nullable
public static List<SubscriptionInfo> getSubscriptions(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager sm = SubscriptionManager.from(context);
return sm.getActiveSubscriptionInfoList();
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 20
收藏 0
点赞 0
评论 0
/**
* @return id of the current subscription (id of SIM)
*/
@Nullable
public static Integer getCurrentSubscriptionId(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionInfo info = getCurrentSubscription(context);
if (info != null) return info.getSubscriptionId();
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 27
收藏 0
点赞 0
评论 0
@Nullable
public static String getCurrentSubscriptionName(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionInfo info = getCurrentSubscription(context);
if (info != null) return info.getDisplayName().toString();
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 20
收藏 0
点赞 0
评论 0
@Nullable
public static SubscriptionInfo getCurrentSubscription(Context context) {
Integer subscriptionId = Settings.getIntegerValue(context, Settings.SIM_SUBSCRIPTION_ID);
if (subscriptionId != null && subscriptionId >= 0) {
return getSubscriptionById(context, subscriptionId);
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 24
收藏 0
点赞 0
评论 0
@Nullable
public static SubscriptionInfo getSubscriptionById(Context context, int subscriptionId) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
List<SubscriptionInfo> list = getSubscriptions(context);
if (list != null) {
for (SubscriptionInfo info : list) {
if (info.getSubscriptionId() == subscriptionId) {
return info;
}
}
}
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 24
收藏 0
点赞 0
评论 0
@Nullable
public static String getName(SubscriptionInfo info) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && info != null) {
return info.getDisplayName().toString();
}
return null;
}
SubscriptionHelper.java 文件源码
项目:BlackList
阅读 21
收藏 0
点赞 0
评论 0
@Nullable
public static Integer getId(SubscriptionInfo info) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && info != null) {
return info.getSubscriptionId();
}
return null;
}
ExampleInstrumentedTest.java 文件源码
项目:BlackList
阅读 43
收藏 0
点赞 0
评论 0
@Test
public void smsSubscriptionManager() throws Exception {
Context context = InstrumentationRegistry.getTargetContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
List<SubscriptionInfo> list = SubscriptionHelper.getSubscriptions(context);
if (list != null) {
int subscriptionId = -1;
for (SubscriptionInfo info : list) {
Log.d("TEST_SmsManager", info.toString());
subscriptionId = info.getSubscriptionId();
}
assertTrue(subscriptionId >= 0);
}
}
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 26
收藏 0
点赞 0
评论 0
private boolean setDefaultVoiceSubscription(final SubscriptionInfo subInfo) {
try {
final TelecomManager telecomManager =
(TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
XposedHelpers.callMethod(telecomManager,
"setUserSelectedOutgoingPhoneAccount",
subscriptionToPhoneAccountHandle(subInfo));
return true;
} catch (Throwable t) {
XposedBridge.log(t);
return false;
}
}
SubscriptionManager.java 文件源码
项目:GravityBox
阅读 20
收藏 0
点赞 0
评论 0
private String getSubDisplayName(final SubscriptionInfo si) {
if (si == null) {
Context gbContext = getGbContext();
return gbContext == null ? "Ask every time" :
gbContext.getString(R.string.sm_voice_ask);
} else {
return si.getDisplayName() == null ?
String.format(Locale.getDefault(), "SIM %d", (si.getSimSlotIndex()+1)) :
si.getDisplayName().toString();
}
}
SubscriptionManagerCompat.java 文件源码
项目:Cable-Android
阅读 23
收藏 0
点赞 0
评论 0
public Optional<SubscriptionInfoCompat> getActiveSubscriptionInfo(int subscriptionId) {
if (Build.VERSION.SDK_INT < 22) {
return Optional.absent();
}
SubscriptionInfo subscriptionInfo = SubscriptionManager.from(context).getActiveSubscriptionInfo(subscriptionId);
if (subscriptionInfo != null) {
return Optional.of(new SubscriptionInfoCompat(subscriptionId, subscriptionInfo.getDisplayName(),
subscriptionInfo.getMcc(), subscriptionInfo.getMnc()));
} else {
return Optional.absent();
}
}
BuilderSimCard.java 文件源码
项目:SmsScheduler
阅读 19
收藏 0
点赞 0
评论 0
@Override
public RadioGroup build() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
return getView();
}
SubscriptionManager subscriptionManager = (SubscriptionManager) activity.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
if (null == subscriptionManager) {
return getView();
}
if (subscriptionManager.getActiveSubscriptionInfoCount() < 2) {
sms.setSubscriptionId(subscriptionManager.getActiveSubscriptionInfoList().get(0).getSubscriptionId());
return getView();
}
getView().setVisibility(View.VISIBLE);
List<Pair<Integer, String>> simCards = new ArrayList<>();
for (SubscriptionInfo info: subscriptionManager.getActiveSubscriptionInfoList()) {
simCards.add(new Pair<>(info.getSubscriptionId(), info.getCarrierName().toString()));
}
RadioButton radio1 = getView().findViewById(R.id.radio_sim1);
RadioButton radio2 = getView().findViewById(R.id.radio_sim2);
prepareRadioButton(radio1, simCards.get(0));
prepareRadioButton(radio2, simCards.get(1));
if (!radio1.isChecked() && !radio2.isChecked()) {
radio1.setChecked(true);
}
return getView();
}
DualNetworkIconData.java 文件源码
项目:Status
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void register() {
if (telephonyManager != null) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && subscriptionManager != null) {
if (networkListener == null) {
int index = 0;
for (SubscriptionInfo info : subscriptionManager.getActiveSubscriptionInfoList()) {
if (info.getSimSlotIndex() > index) {
networkListener = new NetworkListener(info.getSubscriptionId());
index = info.getSimSlotIndex();
}
}
}
}
if (networkListener != null)
telephonyManager.listen(networkListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
isRegistered = true;
}
Util.java 文件源码
项目:android-protwall
阅读 28
收藏 0
点赞 0
评论 0
@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
public static String getSubscriptionInfo(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
return "Not supported";
if (!hasPhoneStatePermission(context))
return "No permission";
StringBuilder sb = new StringBuilder();
SubscriptionManager sm = SubscriptionManager.from(context);
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
sb.append("Slots ")
.append(sm.getActiveSubscriptionInfoCount())
.append('/')
.append(sm.getActiveSubscriptionInfoCountMax())
.append("\r\n");
List<SubscriptionInfo> subscriptions = sm.getActiveSubscriptionInfoList();
if (subscriptions != null)
for (SubscriptionInfo si : subscriptions)
sb.append("SIM ")
.append(si.getSimSlotIndex() + 1)
.append('/')
.append(si.getSubscriptionId())
.append(' ')
.append(si.getCountryIso())
.append('/')
.append(si.getMcc()).append(si.getMnc())
.append(' ')
.append(si.getCarrierName())
.append(si.getDataRoaming() == SubscriptionManager.DATA_ROAMING_ENABLE ? " R" : "")
.append("\r\n");
if (sb.length() > 2)
sb.setLength(sb.length() - 2);
return sb.toString();
}
Phone.java 文件源码
项目:batteryhub
阅读 25
收藏 0
点赞 0
评论 0
/**
* Retrieves network operator names from subscription manager.
* NOTE: Requires SDK level 22 or above
*
* @param context
* @return
*/
private static String getNetworkOperators(Context context) {
String operator = "";
if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
return operator;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
if (subscriptionManager != null) {
List<SubscriptionInfo> subscriptions = subscriptionManager.getActiveSubscriptionInfoList();
if (subscriptions != null) {
for (SubscriptionInfo info : subscriptions) {
CharSequence carrierName = info.getCarrierName();
if (carrierName != null && carrierName.length() > 0) {
operator += carrierName + ";";
}
}
// Remove last delimiter
if (operator.length() >= 1) {
operator = operator.substring(0, operator.length() - 1);
}
}
}
}
return operator;
}
SimCard.java 文件源码
项目:batteryhub
阅读 19
收藏 0
点赞 0
评论 0
/**
* Experimental call to retrieve sim operator names by subscription ids.
*
* @param context Application context
* @return SIM operator name/names with ";" as a delimiter for many.
*/
private static String getSIMOperators(final Context context) {
String operators = "";
if (!PermissionsUtils.checkPermission(context, Manifest.permission.READ_PHONE_STATE)) {
return operators;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
List<SubscriptionInfo> subscriptions = SubscriptionManager.from(context).getActiveSubscriptionInfoList();
if (subscriptions != null && subscriptions.size() > 0) {
for(SubscriptionInfo info : subscriptions){
int subId = info.getSubscriptionId();
String operator = getSimOperatorNameForSubscription(context, subId);
if (operator != null && operator.length() > 0) {
operators += operator + ";";
}
}
// Remove last delimiter
if (operators.length() > 1) {
operators = operators.substring(0, operators.length()-1);
}
}
}
return operators;
}
RNSimDataModule.java 文件源码
项目:react-native-sim-data
阅读 18
收藏 0
点赞 0
评论 0
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
try {
TelephonyManager telManager = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
SubscriptionManager manager = (SubscriptionManager) this.reactContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
List<SubscriptionInfo> subscriptionInfos = manager.getActiveSubscriptionInfoList();
int sub = 0;
for (SubscriptionInfo subInfo : subscriptionInfos) {
CharSequence carrierName = subInfo.getCarrierName();
String countryIso = subInfo.getCountryIso();
int dataRoaming = subInfo.getDataRoaming(); // 1 is enabled ; 0 is disabled
CharSequence displayName = subInfo.getDisplayName();
String iccId = subInfo.getIccId();
int mcc = subInfo.getMcc();
int mnc = subInfo.getMnc();
String number = subInfo.getNumber();
int simSlotIndex = subInfo.getSimSlotIndex();
int subscriptionId = subInfo.getSubscriptionId();
boolean networkRoaming = telManager.isNetworkRoaming();
String deviceId = telManager.getDeviceId(simSlotIndex);
//String deviceId = telManager.getImei(simSlotIndex) || telManager.getMeid(simSlotIndex);
constants.put("carrierName" + sub, carrierName.toString());
constants.put("displayName" + sub, displayName.toString());
constants.put("countryCode" + sub, countryIso);
constants.put("mcc" + sub, mcc);
constants.put("mnc" + sub, mnc);
constants.put("isNetworkRoaming" + sub, networkRoaming);
constants.put("isDataRoaming" + sub, (dataRoaming == 1));
constants.put("simSlotIndex" + sub, simSlotIndex);
constants.put("phoneNumber" + sub, number);
constants.put("deviceId" + sub, deviceId);
constants.put("simSerialNumber" + sub, iccId);
constants.put("subscriptionId" + sub, subscriptionId);
sub++;
}
} catch (Exception e) {
e.printStackTrace();
}
return constants;
}