我想显示图像从服务器的特定id如果图像存在。如果没有图像的id,我想显示一些默认图像,然后我想从相机捕捉图像,剪裁它,然后将该图像加载到服务器,并且我想在第一个活动中显示该加载的图像。如何才能做到这一点。我尝试了一些代码,但如果服务器中没有图像,它会显示一个默认图像,但它不会被第一次上传的图像取代。如果我再次登录,它将显示。如何解决这个问题?用android上传的图像替换默认图像
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_student_details);
{
String IMAGE_URL = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name;
new DownloadImageTask((ImageView) findViewById(R.id.ProfilePicIV))
.execute(IMAGE_URL);
}
public void onResume()
{ // After a pause OR at startup
super.onResume();
getIntent();
String auid_num = auid_s.getText().toString();
String imei_num = imei_s.getText().toString();
String img_name = getIntent().getStringExtra("img_name");
String img_path = getIntent().getStringExtra("img_path");
//Refresh your stuff here
SendDataToServer(auid_num, imei_num);
String IMAGE_URL = "http://xxx.xxx.xx.x/mobile_app/" + img_path + "/" + img_name;
new DownloadImageTask((ImageView) findViewById(R.id.ProfilePicIV))
.execute(IMAGE_URL);
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
xml:
<ImageView
android:id="@+id/ProfilePicIV"
android:layout_width="120dp"
android:layout_height="120dp"
android:background="@drawable/default_image"
android:scaleType="fitXY" />
哪里是你的'DownloadImageTask'方法? –