에서 다운로드 이미지에서 onCreate()에서 호출되지 않습니다 나는 그대로 내 문제도, 내가 This을 보았다 내 에뮬레이터 웹에서 images
을 다운로드하려면 안드로이드에 새로운 해요.AsyncTask를이 <> 웹
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MyAsnyc().execute();
}
public class MyAsnyc extends AsyncTask<Void, Void,Void>{
public File file ;
InputStream is;
protected void inBackground() throws IOException{
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
file = new File(path, "DemoPicture.jpg");
try{
// Make sure the Pictures directory exists.
path.mkdirs();
URL url = new URL(BASE_URL);
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
/*
* Define InputStreams to read from the URLConnection.
*/
is = ucon.getInputStream();
OutputStream os = new FileOutputStream(file);
byte[] data = new byte[is.available()];
is.read(data);
Log.d("MY_TAG>>>", "Picture is Readable...");
os.write(data);
Log.d("MY_TAG>>>", "Picture is Saved...");
is.close();
os.close();
}
catch (IOException e) {
Log.d("ImageManager", "Error: " + e);
}
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
inBackground();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute()
{
try
{
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(null,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
을하지만 내 AsyncTask
중 하나가이 문제를 해결하는 방법과 웹에서 이미지를 다운로드하는 방법 좀 도와주세요 호출되지 않습니다 :하지만 난 이런 짓을했는지.
왜 2 개의 doInBackground() 메소드가 있습니까? 'protected void doInBackground()는 IOException을 던집니다. {'and'protected Void doInBackground (void ... params) {' –
[link] (http://stackoverflow.com/questions/9762057/how-to- url-to-your-android-app에서 download-file-image-download); –
웹에서 이미지 만 다운로드 하시겠습니까? '예'아니면'아니오'입니까? '예'라고 대답한다면 내 눈에는 다른 방법이 있습니다! reply –