提交 309c2f00 编写于 作者: C cmj

see 11/23 log

上级 bed457ee
......@@ -502,7 +502,7 @@ getEntries : 获取压缩文件中的文件对象
***
Gradle:
``` groovy
compile 'com.blankj:utilcode:1.3.3'
compile 'com.blankj:utilcode:1.3.4'
```
### Proguard
......
......@@ -502,7 +502,7 @@ getEntries
***
Gradle:
``` groovy
compile 'com.blankj:utilcode:1.3.3'
compile 'com.blankj:utilcode:1.3.4'
```
### Proguard
......
......@@ -11,6 +11,7 @@ import android.support.annotation.Nullable;
import com.blankj.androidutilcode.App;
import com.blankj.utilcode.utils.LocationUtils;
import com.blankj.utilcode.utils.ThreadPoolUtils;
import com.blankj.utilcode.utils.ToastUtils;
/**
......@@ -23,8 +24,8 @@ import com.blankj.utilcode.utils.ToastUtils;
*/
public class LocationService extends Service {
private boolean isSuccess;
private LocationUtils locationUtils;
private boolean isSuccess;
private LocationUtils locationUtils;
private String lastLatitude = "loading...";
private String lastLongitude = "loading...";
private String latitude = "loading...";
......@@ -33,36 +34,11 @@ public class LocationService extends Service {
private String locality = "loading...";
private String street = "loading...";
private OnGetLocationListener mOnGetLocationListener;
private Thread mThread;
public void setOnGetLocationListener(OnGetLocationListener onGetLocationListener) {
mOnGetLocationListener = onGetLocationListener;
}
@Override
public void onCreate() {
super.onCreate();
mThread = new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
locationUtils = new LocationUtils(App.getInstance());
isSuccess = locationUtils.init(1000, 0, mOnLocationChangeListener);
if (isSuccess) {
ToastUtils.showShortToastSafe(App.getInstance(), "init success");
} else {
ToastUtils.showShortToastSafe(App.getInstance(), "init fail");
if (mOnGetLocationListener != null) {
mOnGetLocationListener.getLocation("unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "unknown");
}
}
Looper.loop();
}
});
mThread.start();
}
private LocationUtils.OnLocationChangeListener mOnLocationChangeListener = new LocationUtils.OnLocationChangeListener() {
@Override
public void getLastKnownLocation(Location location) {
......@@ -80,18 +56,12 @@ public class LocationService extends Service {
if (mOnGetLocationListener != null) {
mOnGetLocationListener.getLocation(lastLatitude, lastLongitude, latitude, longitude, country, locality, street);
}
// 开启新线程来获取地理位置
// new Thread(new Runnable() {
// @Override
// public void run() {
country = locationUtils.getCountryName(Double.parseDouble(latitude), Double.parseDouble(longitude));
locality = locationUtils.getLocality(Double.parseDouble(latitude), Double.parseDouble(longitude));
street = locationUtils.getStreet(Double.parseDouble(latitude), Double.parseDouble(longitude));
if (mOnGetLocationListener != null) {
mOnGetLocationListener.getLocation(lastLatitude, lastLongitude, latitude, longitude, country, locality, street);
}
// }
// }).start();
}
@Override
......@@ -100,6 +70,21 @@ public class LocationService extends Service {
}
};
@Override
public void onCreate() {
super.onCreate();
locationUtils = new LocationUtils(App.getInstance());
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
isSuccess = locationUtils.init(1000, 0, mOnLocationChangeListener);
if (isSuccess) ToastUtils.showShortToastSafe(App.getInstance(), "init success");
Looper.loop();
}
}).start();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
......@@ -114,8 +99,10 @@ public class LocationService extends Service {
@Override
public void onDestroy() {
super.onDestroy();
locationUtils.removeListener();
// 一定要制空,否则内存泄漏
mOnGetLocationListener = null;
super.onDestroy();
}
/**
......
......@@ -32,13 +32,22 @@ public class LocationActivity extends Activity {
tvAboutLocation = (TextView) findViewById(R.id.tv_about_location);
tvAboutLocation.setText("lastLatitude: unknown" +
"\nlastLongitude: unknown" +
"\nlatitude: unknown" +
"\nlongitude: unknown" +
"\ngetCountryName: unknown" +
"\ngetLocality: unknown" +
"\ngetStreet: unknown"
);
bindService(new Intent(this, LocationService.class), conn, Context.BIND_AUTO_CREATE);
}
@Override
protected void onDestroy() {
super.onDestroy();
unbindService(conn);
super.onDestroy();
}
ServiceConnection conn = new ServiceConnection() {
......
###
#### 16/11/23 LocationUtils测试完毕,发布1.3.4
#### 16/11/22 查看LocationActivity内存泄漏
#### 16/11/21 优化README
#### 16/11/20 完善LocationUtils
#### 16/11/19 完善SizeUtils
......
......@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
versionCode 12
versionName "1.3.3"
versionCode 13
versionName "1.3.4"
}
buildTypes {
release {
......@@ -25,5 +25,5 @@ dependencies {
provided 'com.android.support:support-v4:24.0.0'
provided 'com.android.support:design:24.0.0'
}
//apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
apply from: "https://raw.githubusercontent.com/xiaopansky/android-library-publish-to-jcenter/master/bintrayUpload.gradle"
//gradlew bintrayUpload
\ No newline at end of file
......@@ -54,7 +54,9 @@ public class LocationUtils {
* 打开Gps设置界面
*/
public void openGpsSettings() {
mContext.startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
/**
......@@ -76,10 +78,6 @@ public class LocationUtils {
if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
&& !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
ToastUtils.showShortToastSafe(mContext, "无法定位,请打开定位服务");
openGpsSettings();
}
if (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
&& !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
return false;
}
String provider = mLocationManager.getBestProvider(getCriteria(), true);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册