Commit 42aa632f by 韩倩倩

9820E 4.4适配

1 parent a246829f
......@@ -12,7 +12,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.toscl.location.hengfeng"
minSdkVersion 23
minSdkVersion 19
targetSdkVersion 28
versionCode 14
versionName "0.7.8"
......@@ -50,7 +50,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.amap.api:location:4.5.1'
implementation 'com.amap.api:map2d:5.2.0'
implementation("com.squareup.okhttp3:okhttp:3.14.1")
implementation("com.squareup.okhttp3:okhttp:3.12.0")
implementation 'com.google.code.gson:gson:2.8.2'
......
......@@ -12,6 +12,7 @@ import android.graphics.Color;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
......@@ -96,7 +97,7 @@ public class LocationService extends Service {
/*
* 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();
}else{
if (req != null){
......@@ -201,6 +202,8 @@ public class LocationService extends Service {
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ONE_ID,
CHANNEL_ONE_NAME, NotificationManager.IMPORTANCE_HIGH);
notificationChannel.enableLights(true);
......@@ -208,9 +211,10 @@ public class LocationService extends Service {
notificationChannel.setShowBadge(true);
notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
if (manager != null){
if (manager != null) {
manager.createNotificationChannel(notificationChannel);
}
}
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0);
......
......@@ -35,7 +35,7 @@ public class NavActivity extends Activity implements View.OnClickListener {
startActivity(new Intent(this, ServiceInfoActivity.class));
break;
case R.id.service_setting:
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();
}else{
startActivity(new Intent(this, ServiceSettingActivity.class));
......@@ -43,7 +43,7 @@ public class NavActivity extends Activity implements View.OnClickListener {
break;
case R.id.service_stop:
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();
}else if (PreferencesUtil.getInstance(this).getBoolean(PreferencesUtil.HENG_FENG_IS_OEPN, false)
&& PhoneUtils.hengdaServiceAvailable(this)) {
......@@ -53,7 +53,7 @@ public class NavActivity extends Activity implements View.OnClickListener {
}
break;
case R.id.service_apply:
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();
}else{
startActivity(new Intent(this, ServiceApplyActivity.class));
......
......@@ -106,11 +106,11 @@ public class PhoneUtils {
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
Log.d("PHONE", "has network");
Log.d(TAG, "has network");
return mNetworkInfo.isAvailable();
}
}
Log.d("PHONE", "no network");
Log.d(TAG, "no network");
return false;
}
......@@ -450,7 +450,7 @@ public class PhoneUtils {
pattern = Pattern.compile("^((\\+86)|(86))?[1][3456789][0-9]{9}$");
matcher = pattern.matcher(str);
boolean result = !matcher.matches();
Log.d("PHONE", "isMobileNumberInValid:" + result);
Log.d(TAG, "isMobileNumberInValid:" + result);
return result;
}
......@@ -464,7 +464,7 @@ public class PhoneUtils {
public static String getLocalNumber(Context context, int slot) {
String number = "";
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
SubscriptionManager subscriptionManager = (SubscriptionManager) context.getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
SubscriptionInfo subscriptionInfo = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(slot);
......@@ -475,12 +475,30 @@ public class PhoneUtils {
number = getPhoneNumberM(context, subscriptionInfo.getSubscriptionId());
}
}
}else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
number = getPhoneNumberK(context,slot);
}
if (number == null) {
number = "";
}
return number;
}
private static String getPhoneNumberK(Context context,int slotId) {
String result = "";
TelephonyManager tm = getTM(context,slotId);
if(tm != null) {
result = tm.getLine1Number();
}
if(result == null) {
result = "";
}
Log.d(TAG, "getPhoneNumberK " + result);
return result;
}
private static String getPhoneNumberN(Context context, int subId) {
String result = "";
try {
......@@ -494,7 +512,7 @@ public class PhoneUtils {
if (result == null) {
result = "";
}
Log.d("PHONE", "getPhoneNumberN " + result);
Log.d(TAG, "getPhoneNumberN " + result);
return result;
}
......@@ -511,10 +529,24 @@ public class PhoneUtils {
if (result == null) {
result = "";
}
Log.d("PHONE", "getPhoneNumberM " + result);
Log.d(TAG, "getPhoneNumberM " + result);
return result;
}
static public TelephonyManager getTM(Context context,int slotId) {
TelephonyManager telephonyManager = null;
try {
Class<?> c = Class.forName("android.telephony.TelephonyManager");
Method method = c.getMethod("getDefault", int.class);
telephonyManager = (TelephonyManager) (method.invoke(c, slotId));
} catch (Exception e) {
e.printStackTrace();
} finally {
return telephonyManager;
}
}
static public String getProperty(String key, String defaultValue) {
String value = defaultValue;
try {
......@@ -546,13 +578,28 @@ public class PhoneUtils {
// return null != subIds && subIds.length > 0 ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID;
// }
public static int getSubId(Context context, int slotId) {
int subId = -1;
if (Build.VERSION.SDK_INT >= 23) {
final SubscriptionManager subscriptionManager = SubscriptionManager.from(context);
final SubscriptionInfo sir = subscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(slotId);
int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
if (sir != null) {
subId = sir.getSubscriptionId();
}
}else if(Build.VERSION.SDK_INT >= 19){
boolean isSimInsert = false;
TelephonyManager tm = getTM(context,slotId);
if(tm != null) {
Log.d(TAG, "invoke is success");
isSimInsert = tm.hasIccCard();
}
if(isSimInsert){
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);
return subId;
}
......@@ -564,9 +611,16 @@ public class PhoneUtils {
}
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);
try {
if(Build.VERSION.SDK_INT >= 23) {
Class<?> telephonyManagerClazz = telephonyManager.getClass();
Method getSubscriberId = telephonyManagerClazz.getMethod("getSubscriberId", int.class);
imsi = (String) getSubscriberId.invoke(telephonyManager, subId);
}else if (Build.VERSION.SDK_INT >= 19){
TelephonyManager tm = getTM(context,subId);
if(tm != null) {
imsi = tm.getSubscriberId();
}
}
if (imsi == null || imsi.isEmpty()) {
imsi = "" + getProperty(PROPERTY_UIM_SUBSCRIBER_ID[subId], "");
}
......@@ -576,12 +630,12 @@ public class PhoneUtils {
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
} finally {
Log.d("PHONE", "getMccMnc imsi:" + imsi);
Log.d(TAG, "getMccMnc imsi:" + imsi);
//if (imsi != null && imsi.length() > 5) {
// imsi = imsi.substring(0, 5);
// }
if (imsi == null) {
imsi = "";
imsi = "0";
}
return imsi;
}
......@@ -594,6 +648,7 @@ public class PhoneUtils {
//实例化TelephonyManager对象
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String meid = "";
if(Build.VERSION.SDK_INT >= 23) {
try {
Method method = telephonyManager.getClass().getMethod("getDeviceId", int.class);
......@@ -629,17 +684,40 @@ public class PhoneUtils {
} catch (Exception e) {
e.printStackTrace();
}
if (TextUtils.isEmpty(meid)){
try{
if (TextUtils.isEmpty(meid)) {
try {
Method method = telephonyManager.getClass().getMethod("getDeviceId", int.class);
if (TextUtils.isEmpty(meid)){
if (TextUtils.isEmpty(meid)) {
meid = (String) method.invoke(telephonyManager, 0);
}
Log.e(TAG, "meid end:" + meid);
}catch (Exception e){
} catch (Exception e) {
}
}
}else if(Build.VERSION.SDK_INT >= 19){
meid = getProperty("gsm.mtk.meid", "");
if (TextUtils.isEmpty(meid)){
meid = getProperty("persist.radio.us.meid", "");
}
if (TextUtils.isEmpty(meid)){
meid = getProperty("sys.tt.meid", "");
}
if (TextUtils.isEmpty(meid)){
TelephonyManager tm = getTM(context,0);
if(tm != null) {
String deviceId = tm.getDeviceId();
Log.d(TAG,"deviceId:"+deviceId);
if (deviceId != null) {
meid = deviceId;
}
}
}
Log.d(TAG, " K meid:" + meid);
}
return meid;
}
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/color_purple"/>
<corners android:radius="5dp"/>
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/button_focused"/>
<item android:state_focused="false" android:drawable="@drawable/button_unfocused"/>
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/color_white"/>
<corners android:radius="5dp"/>
</shape>
\ No newline at end of file
......@@ -20,7 +20,8 @@
android:focusable="true"
android:text="@string/title_apply"
android:textColor="#000000"
android:textSize="25px" />
android:textSize="25px"
android:background="@drawable/button_selector"/>
</LinearLayout>
<LinearLayout
......@@ -38,6 +39,7 @@
android:text="@string/title_server_stop"
android:textColor="#000000"
android:textSize="25px"
android:background="@drawable/button_selector"
android:visibility="gone"/>
</LinearLayout>
......@@ -56,6 +58,7 @@
android:text="@string/title_service_setting"
android:textColor="#000000"
android:textSize="25px"
android:background="@drawable/button_selector"
android:visibility="gone"/>
</LinearLayout>
......@@ -72,7 +75,8 @@
android:focusable="true"
android:text="@string/title_server_info"
android:textColor="#000000"
android:textSize="25px" />
android:textSize="25px"
android:background="@drawable/button_selector"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -3,4 +3,6 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="color_purple">#FF80FF</color>
<color name="color_white">#ffffff</color>
</resources>
......@@ -5,8 +5,17 @@
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:textColor">#000000</item>
<item name="android:actionBarStyle">@style/Customize_Holo_ActionBar</item>
<item name="android:actionBarSize">62dp</item>
</style>
<style name="Customize_Holo_ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#008577</item>
<item name="android:titleTextStyle">@style/Customize_AcBar_titleStyle</item>
</style>
<style name="Customize_AcBar_titleStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textSize">25sp</item>
<item name="android:textColor">#ffffff</item>
</style>
<style name="InputBoxStyle">
<item name="android:layout_centerHorizontal">true</item>
<item name="android:layout_marginLeft">18dp</item>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!