首先簡單地創建VedioDownloader類並把下載的URL的錄象和mainactivity調用這個類中的線程
import android.os.Environment;
import android.util.Log;
public class VedioDownloader implements Runnable {
String vedio_URL = "http://daily3gp.com/vids/747.3gp";
//if download image then simply pass image url such as
//String image_URL = "http://www.appliconic.com/screen.jpg";
public void run() {
// TODO Auto-generated method stub
HttpURLConnection conn = null;
URL url = null;
try {
url = new URL(vedio_URLL);
} catch (MalformedURLException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
conn = (HttpURLConnection) url.openConnection();
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
conn.setDoInput(true);
try {
conn.connect();
Log.d("Connection", "Connection Established");
InputStream input = conn.getInputStream();
File storagePath = Environment.getExternalStorageDirectory();
OutputStream output = new FileOutputStream(new File(storagePath,
"vedio.3gp"));
Log.d("1", "1");
byte[] buffer = new byte[input.available()];
int bytesRead = 0;
while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
output.write(buffer, 0, bytesRead);
}
Log.d("2", "2");
output.close();
input.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
MainActivity類別
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("aftar thread","befor thread");
Thread objThread=new Thread(new VedioDownloader());
objThread.start();
Log.d("aftar thread","fater thread");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
謝謝回覆。我正在和其他人討論這個問題,他們正在討論爲多個圖像創建一個URL。我似乎無法圍繞如何在應用程序端工作。這聽起來是對的嗎?有沒有創建超過100個網址(每個資源文件1個)的方法?我們正在看Android的應用程序。當您單擊某個相冊時,該相冊中的圖片會以縮略圖的形式顯示,然後您可以單擊縮略圖以全屏顯示。當你點擊下一步時,沒有加載(下一個圖像已經加載)。 – Brian 2011-02-03 21:41:31