Commit e4abb500 by hanqianqian

去掉手机号码前缀 + 无论插卡1或插卡2,定位服务都能正常使用

1 parent ac7813ae
...@@ -38,7 +38,7 @@ public class ServiceApplyActivity extends Activity implements View.OnClickListen ...@@ -38,7 +38,7 @@ public class ServiceApplyActivity extends Activity implements View.OnClickListen
/* /*
* has sim card ? * has sim card ?
* */ * */
if (PhoneUtils.getSubId(this, PreferencesUtil.HENG_FENG_DEFAULT_SLOT) == SubscriptionManager.INVALID_SUBSCRIPTION_ID){ if (PhoneUtils.getSubId(this, PreferencesUtil.HENG_FENG_DEFAULT_SLOT) == -1){
Toast.makeText(this, getResources().getString(R.string.location_service_failed_tips), Toast.LENGTH_SHORT).show(); Toast.makeText(this, getResources().getString(R.string.location_service_failed_tips), Toast.LENGTH_SHORT).show();
finish(); finish();
} }
......
...@@ -48,6 +48,8 @@ public class PhoneUtils { ...@@ -48,6 +48,8 @@ public class PhoneUtils {
private static final String TAG = "PhoneUtils"; private static final String TAG = "PhoneUtils";
private static final ArrayMap<String, String> mobileAlias = new ArrayMap<>(); private static final ArrayMap<String, String> mobileAlias = new ArrayMap<>();
private static boolean mDebugTest = false; private static boolean mDebugTest = false;
public static final int SIM_CARD_1 = 0;
public static final int SIM_CARD_2 = 1;
public static int getSimState(int slot) { public static int getSimState(int slot) {
int state = -1; int state = -1;
...@@ -476,11 +478,19 @@ public class PhoneUtils { ...@@ -476,11 +478,19 @@ public class PhoneUtils {
} }
} }
}else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){ }else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
number = getPhoneNumberK(context,slot); int simId = getSubId(context,PreferencesUtil.HENG_FENG_DEFAULT_SLOT);
if(simId == -1){
simId = slot;
}
number = getPhoneNumberK(context,simId);
} }
if (number == null) { if (number == null) {
number = ""; number = "";
} }
String prefix = "+86";
if(!TextUtils.isEmpty(number)) {
number = trimNum(prefix,number);
}
return number; return number;
} }
...@@ -588,21 +598,28 @@ public class PhoneUtils { ...@@ -588,21 +598,28 @@ public class PhoneUtils {
} }
}else if(Build.VERSION.SDK_INT >= 19){ }else if(Build.VERSION.SDK_INT >= 19){
boolean isSimInsert = false; boolean isSimInsert = false;
TelephonyManager tm = getTM(context,slotId); if(isSimInserted(context,SIM_CARD_1)){
if(tm != null) { return SIM_CARD_1;
isSimInsert = tm.hasIccCard();
} }
if(isSimInserted(context,SIM_CARD_2)){
if(isSimInsert){ return SIM_CARD_2;
subId = slotId + 1;
} }
Log.d("qqh","Sim is insert:"+isSimInsert);
} }
Log.d(TAG, "sdk:"+Build.VERSION.SDK_INT);
Log.d(TAG, "getSubid slotid: " + slotId + ", subid: " + subId); Log.d(TAG, "getSubid slotid: " + slotId + ", subid: " + subId);
return subId; return subId;
} }
public static boolean isSimInserted(Context context,int slotId) {
boolean isSimInsert = false;
TelephonyManager tm = getTM(context, slotId);
if (tm != null) {
isSimInsert = tm.hasIccCard();
}
return isSimInsert;
}
public static String getMccMnc(Context context, int subId) { public static String getMccMnc(Context context, int subId) {
String imsi = ""; String imsi = "";
if (subId < 0) { if (subId < 0) {
...@@ -615,7 +632,10 @@ public class PhoneUtils { ...@@ -615,7 +632,10 @@ public class PhoneUtils {
Method getSubscriberId = telephonyManagerClazz.getMethod("getSubscriberId", int.class); Method getSubscriberId = telephonyManagerClazz.getMethod("getSubscriberId", int.class);
imsi = (String) getSubscriberId.invoke(telephonyManager, subId); imsi = (String) getSubscriberId.invoke(telephonyManager, subId);
}else if (Build.VERSION.SDK_INT >= 19){ }else if (Build.VERSION.SDK_INT >= 19){
TelephonyManager tm = getTM(context,0); if(subId == -1){
subId = 0;
}
TelephonyManager tm = getTM(context,subId);
if(tm != null) { if(tm != null) {
imsi = tm.getSubscriberId(); imsi = tm.getSubscriberId();
} }
...@@ -705,7 +725,11 @@ public class PhoneUtils { ...@@ -705,7 +725,11 @@ public class PhoneUtils {
} }
if (TextUtils.isEmpty(meid)){ if (TextUtils.isEmpty(meid)){
TelephonyManager tm = getTM(context,0); int simId = getSubId(context,PreferencesUtil.HENG_FENG_DEFAULT_SLOT);
if(simId == -1){
simId = 0;
}
TelephonyManager tm = getTM(context,simId);
if(tm != null) { if(tm != null) {
String deviceId = tm.getDeviceId(); String deviceId = tm.getDeviceId();
if (deviceId != null) { if (deviceId != null) {
...@@ -713,7 +737,6 @@ public class PhoneUtils { ...@@ -713,7 +737,6 @@ public class PhoneUtils {
} }
} }
} }
Log.d(TAG, " K meid:" + meid); Log.d(TAG, " K meid:" + meid);
} }
return meid; return meid;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!