|
|
|
@ -8,6 +8,10 @@ import android.content.pm.PackageManager;
|
|
|
|
|
import android.graphics.Path;
|
|
|
|
|
import android.graphics.SurfaceTexture;
|
|
|
|
|
import android.hardware.Camera;
|
|
|
|
|
import android.location.Location;
|
|
|
|
|
import android.location.LocationListener;
|
|
|
|
|
import android.location.LocationManager;
|
|
|
|
|
import android.media.MediaRecorder;
|
|
|
|
|
import android.os.Build;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.os.Handler;
|
|
|
|
@ -25,9 +29,12 @@ import android.util.Log;
|
|
|
|
|
import android.view.Display;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.WindowManager;
|
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.dowse.camera.client.DSCameraManager;
|
|
|
|
|
import com.xinyingpower.microphoto.databinding.ActivityMainBinding;
|
|
|
|
|
//import com.xinyingpower.microphoto.request.INettyMessageListener;
|
|
|
|
|
//import com.xinyingpower.microphoto.request.NettyChatClient;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.File;
|
|
|
|
@ -55,18 +62,22 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
static {
|
|
|
|
|
System.loadLibrary("microphoto");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ActivityMainBinding binding;
|
|
|
|
|
private int defaultDataSubId;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDestroy() {
|
|
|
|
|
super.onDestroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class AppConfig {
|
|
|
|
|
public String cmdid;
|
|
|
|
|
public String server;
|
|
|
|
|
public int port;
|
|
|
|
|
public int protocol;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
@ -95,14 +106,9 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
|
|
|
|
|
String[] accessPermissions = new String[]{
|
|
|
|
|
Manifest.permission.CAMERA,
|
|
|
|
|
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
|
|
|
|
Manifest.permission.FOREGROUND_SERVICE,
|
|
|
|
|
Manifest.permission.READ_PHONE_STATE,
|
|
|
|
|
String[] accessPermissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.FOREGROUND_SERVICE, Manifest.permission.READ_PHONE_STATE,
|
|
|
|
|
/*Manifest.permission.PACKAGE_USAGE_STATS,*/
|
|
|
|
|
/*Manifest.permission.SET_TIME,*/
|
|
|
|
|
};
|
|
|
|
|
/*Manifest.permission.SET_TIME,*/};
|
|
|
|
|
boolean needRequire = false;
|
|
|
|
|
for (String access : accessPermissions) {
|
|
|
|
|
int curPermission = ActivityCompat.checkSelfPermission(MainActivity.this, access);
|
|
|
|
@ -112,10 +118,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (needRequire) {
|
|
|
|
|
ActivityCompat.requestPermissions(
|
|
|
|
|
MainActivity.this,
|
|
|
|
|
accessPermissions,
|
|
|
|
|
MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE);
|
|
|
|
|
ActivityCompat.requestPermissions(MainActivity.this, accessPermissions, MY_PERMISSIONS_REQUEST_FOREGROUND_SERVICE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -212,6 +215,51 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
binding.gps.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
// gpsTake();
|
|
|
|
|
startLocate();
|
|
|
|
|
// LocationUtils.unregister();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.netgps.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
// startLocate();
|
|
|
|
|
boolean gpsEnabled = LocationUtils.isGpsEnabled(MainActivity.this);
|
|
|
|
|
System.out.printf("g" + gpsEnabled);
|
|
|
|
|
LocationUtils.register(MainActivity.this, 0, 0, new LocationUtils.OnLocationChangeListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void getLastKnownLocation(Location location) {
|
|
|
|
|
Log.e("xyh", "onLocationChanged: " + location.getLatitude());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
|
//位置信息变化时触发
|
|
|
|
|
Log.e("xyh", "定位方式:" + location.getProvider());
|
|
|
|
|
Log.e("xyh", "纬度:" + location.getLatitude());
|
|
|
|
|
Log.e("xyh", "经度:" + location.getLongitude());
|
|
|
|
|
Log.e("xyh", "海拔:" + location.getAltitude());
|
|
|
|
|
Log.e("xyh", "时间:" + location.getTime());
|
|
|
|
|
Log.e("xyh", "国家:" + LocationUtils.getCountryName(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "获取地理位置:" + LocationUtils.getAddress(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "所在地:" + LocationUtils.getLocality(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "所在街道:" + LocationUtils.getStreet(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
|
|
|
|
System.out.println("dfsad");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(appConfig.cmdid) && !TextUtils.isEmpty(appConfig.server) && appConfig.port != 0) {
|
|
|
|
|
Handler handler = new Handler();
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
@ -225,6 +273,63 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
handler.postDelayed(runnable, 5000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
binding.tcpudp.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
// initSocket();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
binding.tcpudpsend.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
// byte[] bytes = {(byte) 0xA5, 0x5A, 0x04, 0x00, 0x58, 0x59, 0x49, 0x47, 0x51, 0x31, 0x30, 0x44, 0x32, 0x32, 0x31, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x07, (byte) 0xE7, 0x37, (byte) 0x86, (byte) 0x96, (byte) 0xD4, 0x64, (byte) 0xB5, (byte) 0xFB, (byte) 0x96};
|
|
|
|
|
byte[] bytes = {(byte) 0xA5, 0x5A, 0x04, 0x00, 0x58, 0x59, 0x49, 0x47, 0x51, 0x31, 0x30, 0x44, 0x32, 0x32, 0x31, 0x30, 0x30, 0x30, 0x31, 0x30, 0x30, 0x07, (byte) 0xE6, (byte) 0xEA, 0x52, (byte) 0xB7, (byte) 0xD4, 0x64, 0x5C, 0x7E, (byte) 0x96};
|
|
|
|
|
// NettyChatClient.getInstance().sendByteMessage(bytes);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
binding.video.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
//方法1
|
|
|
|
|
|
|
|
|
|
// mediaRecorder = new MediaRecorder();
|
|
|
|
|
//
|
|
|
|
|
// //设置视频和音频的来源
|
|
|
|
|
// mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
|
|
|
|
// mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
|
|
|
|
// //
|
|
|
|
|
// mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
|
|
|
|
// //设置录制视频的编码格式
|
|
|
|
|
// mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
|
|
|
|
|
// //设置音频的编码格式
|
|
|
|
|
// mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
|
|
|
|
|
// //设置视频的帧率:每秒切换图片的次数
|
|
|
|
|
// mediaRecorder.setVideoFrameRate(20);
|
|
|
|
|
// //视频的分辨率
|
|
|
|
|
// mediaRecorder.setVideoSize(176, 144);
|
|
|
|
|
//
|
|
|
|
|
//// mediaRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
|
|
|
|
|
//
|
|
|
|
|
// mediaRecorder.setOutputFile(Environment.getExternalStorageDirectory().getAbsolutePath()+"/111.mp4");
|
|
|
|
|
// try {
|
|
|
|
|
// mediaRecorder.prepare();
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// // TODO Auto-generated catch block
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// }
|
|
|
|
|
// mediaRecorder.start();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
binding.video2.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
// mediaRecorder.stop();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setDefaultDataSubId(int subId) {
|
|
|
|
@ -268,8 +373,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
} finally {
|
|
|
|
|
if (inputStreamReader != null) {
|
|
|
|
|
try {
|
|
|
|
|
inputStreamReader.close();
|
|
|
|
@ -303,8 +407,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
} finally {
|
|
|
|
|
if (outputStreamWriter != null) {
|
|
|
|
|
try {
|
|
|
|
|
outputStreamWriter.close();
|
|
|
|
@ -447,4 +550,123 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
public native String stringFromJNI();
|
|
|
|
|
|
|
|
|
|
public native boolean takePhoto(int channel, int preset, String path, String fileName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
|
// 处理位置更新事件
|
|
|
|
|
double latitude = location.getLatitude();
|
|
|
|
|
double longitude = location.getLongitude();
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
|
|
Log.e("xyh", "定位方式:" + location.getProvider());
|
|
|
|
|
Log.e("xyh", "纬度:" + location.getLatitude());
|
|
|
|
|
Log.e("xyh", "经度:" + location.getLongitude());
|
|
|
|
|
Log.e("xyh", "海拔:" + location.getAltitude());
|
|
|
|
|
Log.e("xyh", "时间:" + location.getTime());
|
|
|
|
|
Log.e("xyh", "国家:" + LocationUtils.getCountryName(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "获取地理位置:" + LocationUtils.getAddress(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "所在地:" + LocationUtils.getLocality(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
Log.e("xyh", "所在街道:" + LocationUtils.getStreet(MainActivity.this, location.getLatitude(), location.getLongitude()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onStatusChanged(String provider, int status, Bundle extras) {
|
|
|
|
|
// 处理位置状态变化事件
|
|
|
|
|
System.out.printf("fsdaf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onProviderEnabled(String provider) {
|
|
|
|
|
// 处理位置提供者启用事件
|
|
|
|
|
System.out.printf("fsdaf");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
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已开启
|
|
|
|
|
/**
|
|
|
|
|
* 绑定监听
|
|
|
|
|
* 参数1,设备:有GPS_PROVIDER和NETWORK_PROVIDER两种,前者是GPS,后者是GPRS以及WIFI定位
|
|
|
|
|
* 参数2,位置信息更新周期.单位是毫秒
|
|
|
|
|
* 参数3,位置变化最小距离:当位置距离变化超过此值时,将更新位置信息
|
|
|
|
|
* 参数4,监听
|
|
|
|
|
* 备注:参数2和3,如果参数3不为0,则以参数3为准;参数3为0,则通过时间来定时更新;两者为0,则随时刷新
|
|
|
|
|
*/
|
|
|
|
|
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();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
}
|