最初単にVedioDownloaderクラスを作成し、ダウンロード用のURLにvedioのを渡すと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以上のURL(各リソースファイルごとに1つ)を作成することでそれを行う方法はありますか?私たちはAndroidのfacebookアプリを見ていました。アルバムをクリックすると、アルバム内の画像がサムネイルとして表示され、サムネイルをクリックすると全画面に移動できます。次をクリックすると、読み込みは行われません(次のイメージは既に読み込まれています)。 – Brian
Androidのブラウザからfacebookに行き、同じプロセスを経ると、次のボタンが押されたときに次の画像を読み込む必要があります。ご協力いただきありがとうございます。 – Brian
私は、Facebookのアプリが、おそらくXMLのリストにある画像のリストを呼び出すと仮定します。次に、それぞれの画像をバックグラウンドで交互にロードします。おそらく現在表示しているものの横にあるものを読み込みます。 複数の画像を1つのファイルに保存すると、ファイルをzipアーカイブに入れてダウンロードすることができます。しかし、それはあなたがただ見たいと思ったとしてもすべてのイメージをダウンロードすることを余儀なくされるので、読み込み時間が遅くなるでしょう。 –