【发布时间】:2019-06-12 15:14:31
【问题描述】:
我使用base 64的方法将图像转换成字符串,然后使用retrofit将其存储在数据库中并调用它并在Android模拟器中显示它,但是将其转换为Mobile中的APK后没有见过 apiInterface = login_client.getApiClient().create(login_interface.class);
retrofit2.Call<Info> call = apiInterface.getinfo(strimage);
call.enqueue(new Callback<Info>() {
@Override
public void onResponse(Call<Info> call, Response<Info> response) {
strimage=response.body().getImgnameinfo();
Toast.makeText(Login_Activity.this, strimage, Toast.LENGTH_SHORT).show();
imagtest.setImageBitmap(StringToBitMap(strimage));
imagtest.bringToFront();
}
@Override
public void onFailure(Call<Info> call, Throwable t) {
}
});
public static Bitmap StringToBitMap(String image) {
try {
byte[] encodeByte = Base64.decode(image.getBytes(), Base64.DEFAULT);
final Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0,
encodeByte.length);
return bitmap;
} catch (Exception e) {
e.getMessage();
return null;
}
}
【问题讨论】:
-
您能提供更多信息吗?例如,您的模拟器中的 android 版本以及您正在测试的手机上的 android 版本。此外,您在
AndroidManifiest.xml文件中将以下权限添加到<uses-permission android: name = "android.permission.READ_EXTERNAL_STORAGE" />和<uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" />
标签: android