本文整理汇总了Java中android.telephony.SubscriptionInfo.getSubscriptionId方法的典型用法代码示例。如果您正苦于以下问题:Java SubscriptionInfo.getSubscriptionId方法的具体用法?Java SubscriptionInfo.getSubscriptionId怎么用?Java SubscriptionInfo.getSubscriptionId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.telephony.SubscriptionInfo
的用法示例。
在下文中一共展示了SubscriptionInfo.getSubscriptionId方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: subscriptionToPhoneAccountHandle
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
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;
}
示例2: sendSms
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@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();
}
}
}
示例3: getCurrentSubscriptionId
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
/**
* @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;
}
示例4: getSubscriptionById
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@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;
}
示例5: getId
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@Nullable
public static Integer getId(SubscriptionInfo info) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1 && info != null) {
return info.getSubscriptionId();
}
return null;
}
示例6: smsSubscriptionManager
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@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);
}
}
}
示例7: register
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@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;
}
示例8: getSIMOperators
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
/**
* 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;
}
示例9: getConstants
import android.telephony.SubscriptionInfo; //导入方法依赖的package包/类
@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;
}