优化代码

MQTTtest
Matthew 10 months ago
parent ad97372615
commit 34c6f8c341

@ -576,21 +576,6 @@ public class MainActivity extends AppCompatActivity {
} }
} }
private void setDefaultDataSubId(int subId) {
SubscriptionManager subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
try {
Method method = subscriptionManager.getClass().getDeclaredMethod("setDefaultDataSubId", int.class);
method.invoke(subscriptionManager, subId);
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
Method method1 = telephonyManager.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
method1.invoke(telephonyManager, true);
} catch (Exception e) {
Log.e(TAG, "wjz debug setDefaultDataSubId: error is " + e.getMessage());
}
}
private MicroPhotoContext.AppConfig retrieveAndSaveAppConfig() { private MicroPhotoContext.AppConfig retrieveAndSaveAppConfig() {
MicroPhotoContext.AppConfig appConfig = new MicroPhotoContext.AppConfig(); MicroPhotoContext.AppConfig appConfig = new MicroPhotoContext.AppConfig();
@ -618,7 +603,7 @@ public class MainActivity extends AppCompatActivity {
} }
private MicroPhotoContext.AppConfig getAppConfig() { private MicroPhotoContext.AppConfig getAppConfig() {
return MicroPhotoContext.getMpAppConfig(this.getApplicationContext()); return MicroPhotoContext.getMpAppConfig(getApplicationContext());
} }
private void saveAppConfig(MicroPhotoContext.AppConfig appConfig) { private void saveAppConfig(MicroPhotoContext.AppConfig appConfig) {
@ -636,23 +621,6 @@ public class MainActivity extends AppCompatActivity {
return 0; return 0;
} }
private void gpsTake() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// 注册位置监听器
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKnownLocation != null) {
double latitude = lastKnownLocation.getLatitude();
double longitude = lastKnownLocation.getLongitude();
// 处理最新位置信息
System.out.printf("gps" + latitude + "fds:" + longitude);
}
}
LocationListener locationListener = new LocationListener() { LocationListener locationListener = new LocationListener() {
@Override @Override
public void onLocationChanged(Location location) { public void onLocationChanged(Location location) {
@ -676,83 +644,20 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
// 处理位置状态变化事件 // 处理位置状态变化事件
System.out.printf("fsdaf");
} }
@Override @Override
public void onProviderEnabled(String provider) { public void onProviderEnabled(String provider) {
// 处理位置提供者启用事件 // 处理位置提供者启用事件
System.out.printf("fsdaf");
} }
@Override @Override
public void onProviderDisabled(String provider) { public void onProviderDisabled(String provider) {
// 处理位置提供者禁用事件 // 处理位置提供者禁用事件
System.out.printf("fsdaf");
} }
}; };
private void startLocate() {
LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
boolean providerEnabled = mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (providerEnabled) { //GPS已开启
/**
*
* 1GPS_PROVIDERNETWORK_PROVIDERGPS,GPRSWIFI
* 2.
* 3
* 4
* 23303300
*/
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
} else {
Toast.makeText(this, "请打开GPS", Toast.LENGTH_SHORT).show();
}
}
// private void initSocket() {
// NettyChatClient nettyChatClient = NettyChatClient.newInstance("47.96.238.157", 6891);
//// NettyChatClient nettyChatClient = NettyChatClient.newInstance("180.166.218.222", 40032);
// nettyChatClient.init(new INettyMessageListener() {
// @Override
// public void onReceive(String message) {
//// for (INettyMessageListener nettyMessageListener : mIMessageListenerList) {
//// nettyMessageListener.onReceive(message);
//// }
// System.out.println("dsfa");
// }
//
// @Override
// public void onConnectSuccess() {
//// for (INettyMessageListener nettyMessageListener : mIMessageListenerList) {
//// nettyMessageListener.onConnectSuccess();
//// }
// System.out.println("dsfa");
// }
//
// @Override
// public void onError() {
//// for (INettyMessageListener nettyMessageListener : mIMessageListenerList) {
//// nettyMessageListener.onError();
//// }
// System.out.println("dsfa");
// }
// });
// nettyChatClient.connect();
// }
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {

Loading…
Cancel
Save