2024.5.15(第二阶段冲刺第三天)
所学时间:2.5小时
代码行数:98行
博客园数:1篇
所学知识:
1.我昨天的成就:解决相机出现的问题
2.遇到什么困难:在显示上出现问题,拍摄的照片无法显示到ListVIew里。
3.今天的任务:把拍完的照片显示到页面上。
4.今天所敲的代码:
public void onActivityResult(ActivityResult result)
{
if (result.getResultCode() == -1)
{
Intent intent = result.getData();
imageUri = intent.getData();
String real= Utils.getRealPath(requireContext(),intent);
Log.e("real",real);
file=new File(real);
scImage();
if (imageUri != null)
{
String dizhi=getRealPathFromUri(imageUri);
Log.e("aaaaaaa",dizhi);
img_result.setImageURI(imageUri);
new Thread(new Runnable() {
@Override
public void run() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://172.20.10.3:8080/getFish/getWuRanFish")
.build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
Gson gson = new Gson();
Type resultType = new TypeToken<Result<Integer>>() {}.getType();
Result<FishData> r = gson.fromJson(response.body().string(), resultType);
data = r.getResult();
System.out.println("Received data: " + data);
} else {
System.out.println("Request failed: " + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}
{
if (result.getResultCode() == -1)
{
Intent intent = result.getData();
imageUri = intent.getData();
String real= Utils.getRealPath(requireContext(),intent);
Log.e("real",real);
file=new File(real);
scImage();
if (imageUri != null)
{
String dizhi=getRealPathFromUri(imageUri);
Log.e("aaaaaaa",dizhi);
img_result.setImageURI(imageUri);
new Thread(new Runnable() {
@Override
public void run() {
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("http://172.20.10.3:8080/getFish/getWuRanFish")
.build();
try {
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
Gson gson = new Gson();
Type resultType = new TypeToken<Result<Integer>>() {}.getType();
Result<FishData> r = gson.fromJson(response.body().string(), resultType);
data = r.getResult();
System.out.println("Received data: " + data);
} else {
System.out.println("Request failed: " + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}