Commit 42aa632f by 韩倩倩

9820E 4.4适配

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