本文整理汇总了Java中android.telephony.SubscriptionManager类的典型用法代码示例。如果您正苦于以下问题:Java SubscriptionManager类的具体用法?Java SubscriptionManager怎么用?Java SubscriptionManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SubscriptionManager类属于android.telephony包,在下文中一共展示了SubscriptionManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActiveSubscriptionInfoList
import android.telephony.SubscriptionManager; //导入依赖的package包/类
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;
}
示例2: onHandleIntent
import android.telephony.SubscriptionManager; //导入依赖的package包/类
@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) );
}
}
示例3: getActiveSubscriptionInfoList
import android.telephony.SubscriptionManager; //导入依赖的package包/类
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;
}
示例4: fillDualSimList
import android.telephony.SubscriptionManager; //导入依赖的package包/类
@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());
}
示例5: getPreferredSubscriptionId
import android.telephony.SubscriptionManager; //导入依赖的package包/类
public Optional<Integer> getPreferredSubscriptionId() {
if (Build.VERSION.SDK_INT < 24) {
return Optional.absent();
}
return Optional.of(SubscriptionManager.getDefaultSmsSubscriptionId());
}
示例6: getActiveSubscriptionInfo
import android.telephony.SubscriptionManager; //导入依赖的package包/类
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();
}
}
示例7: sendSms
import android.telephony.SubscriptionManager; //导入依赖的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();
}
}
}
示例8: isDualSim
import android.telephony.SubscriptionManager; //导入依赖的package包/类
public static boolean isDualSim(final Context context)
{
try
{
final SubscriptionManager sm = SubscriptionManager.from(context);
final int activeSubscriptionInfoCount = sm.getActiveSubscriptionInfoCount();
//System.out.println("active subscription count: " + activeSubscriptionInfoCount);
return activeSubscriptionInfoCount > 1;
}
catch (Throwable t)
{
//t.printStackTrace();
return false;
}
}
示例9: getSubscriptions
import android.telephony.SubscriptionManager; //导入依赖的package包/类
@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;
}
示例10: getActiveSubscriptionInfo
import android.telephony.SubscriptionManager; //导入依赖的package包/类
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();
}
}
示例11: prepareSendSms
import android.telephony.SubscriptionManager; //导入依赖的package包/类
@Override
public void prepareSendSms() {
if (view != null && needDialog) {
view.showLoading();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager mSubscriptionManager = SubscriptionManager.from(context);
subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null && subInfoList.size() > 1) {
carriersICC.add(0, subInfoList.get(0).getSubscriptionId());
carriersICC.add(1, subInfoList.get(1).getSubscriptionId());
carriersNAME.add(0, subInfoList.get(0).getCarrierName().toString());
carriersNAME.add(1, subInfoList.get(1).getCarrierName().toString());
view.hideLoading();
view.renderSimChooserView(context, carriersNAME.get(0), carriersNAME.get(1));
} else {
carriersICC.add(0, subInfoList.get(0).getSubscriptionId());
carriersNAME.add(0, subInfoList.get(0).getCarrierName().toString());
sendSmsFromSubscriptionIdIndex(0);
}
} else {
sendSmsForOldPhones();
}
}
示例12: build
import android.telephony.SubscriptionManager; //导入依赖的package包/类
@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();
}
示例13: getSmsManager
import android.telephony.SubscriptionManager; //导入依赖的package包/类
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);
}
示例14: DualNetworkIconData
import android.telephony.SubscriptionManager; //导入依赖的package包/类
public DualNetworkIconData(Context context) {
super(context);
telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
subscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
}
示例15: setMobileNetwork
import android.telephony.SubscriptionManager; //导入依赖的package包/类
public void setMobileNetwork(Context context, int targetState) {
if (!Utils.isReadPhoneStatePermissionGranted(context)) {
grantReadPhoneStatePermission();
}
String command;
try {
String transactionCode = getTransactionCode(context);
SubscriptionManager mSubscriptionManager = (SubscriptionManager) context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
for (int i = 0; i < mSubscriptionManager.getActiveSubscriptionInfoCountMax(); i++) {
if (transactionCode != null && transactionCode.length() > 0) {
int subscriptionId = mSubscriptionManager.getActiveSubscriptionInfoList().get(i).getSubscriptionId();
command = "service call phone " + transactionCode + " i32 " + subscriptionId + " i32 " + targetState;
List<String> output = Shell.SU.run(command);
if (output != null) {
for (String s : output) {
Log.i(TAG, s);
}
} else {
Log.i(TAG, "Error occurred while executing command (" + command + ")");
}
}
}
} catch (Exception e) {
Log.i(TAG, "Failed to toggle mobile data: " + e.getMessage());
}
}