Be happy

안드로이드 스튜디오로 웹서버로 전송하기 본문

Fish in my hands (2018.3~2018.6)/안드로이드 스튜디오

안드로이드 스튜디오로 웹서버로 전송하기

해퓌해퓌 2018. 6. 22. 23:32

private void getImage1() {

String id = editTextId.getText().toString().trim();

class GetImage1 extends AsyncTask<String, Void, Bitmap> {
ProgressDialog loading;

@Override
protected void onPreExecute() {
super.onPreExecute();
loading = ProgressDialog.show(Book.this, "Uploading...", null, true, true);
}

@Override
protected void onPostExecute(Bitmap b) {
super.onPostExecute(b);
loading.dismiss();
imageView1.setImageBitmap(b);
}

@Override
protected Bitmap doInBackground(String... params) {
String id = params[0];

String add1 = "url 주소";

URL url1 = null;

Bitmap image1 = null;

try {
url1 = new URL(add1);
image1 = BitmapFactory.decodeStream(url1.openConnection().getInputStream());

PublicValues.Book_bitmap1 = image1;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return image1;
}
}

GetImage1 gi1 = new GetImage1();
gi1.execute(id);
}


우선, db에 저장할 이미지를 이미지를 불러옵니다.

그리고 AsyncTask 기능을 사용하여


add1 = php 주소로 저장하고,

원래쓰실 image를 텍스트형태로 바꿉니다

image1 = BitmapFactory.decodeStream(url1.openConnection().getInputStream());


그리고 그 텍스트화된이미지를 php에 같이 보냅니다.


http://prettymen.tistory.com/37?category=753669


Comments