導航:首頁 > 操作系統 > android下載圖

android下載圖

發布時間:2023-06-07 17:12:56

android下載圖片和視頻到本地,求代碼,求案例

下面是android多線程下載例子截圖:

java">packagemm.shandong.com.testmultithreaddownload;
importandroid.app.ProgressDialog;
importandroid.content.Intent;
importandroid.net.Uri;
importandroid.os.Environment;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.text.TextUtils;
importandroid.view.View;
importandroid.widget.EditText;
importandroid.widget.Toast;
importjava.io.File;
importmm.shandong.com.testmultithreaddownload.thread.UpdateUIThread;
importmm.shandong.com.testmultithreaddownload.util.FileUtil;
{
ProgressDialogpb;
EditTexteditText;
Handlerhandler;
=null;
///文件路徑
privateStringurl=
"http://gdown..com/data/wisegame/3c00add7144d3915/kugouyinle.apk";
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_multi_thread_down_load);
editText=(EditText)findViewById(R.id.editText);
initHandler();
}
publicvoidinitHandler(){
handler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
switch(msg.what){
caseFileUtil.startDownloadMeg:
pb.setMax(mUpdateUIThread.getFileSize());//開始
break;
caseFileUtil.updateDownloadMeg:
if(!mUpdateUIThread.isCompleted())//下載進度消息
{
pb.setProgress(mUpdateUIThread.getDownloadSize());
pb.setMessage("下載速度:"+
mUpdateUIThread.getDownloadSpeed()+"k/秒"+
"下載百分比"+mUpdateUIThread.getDownloadPercent()+"%");
}else{
pb.setMessage("下載完成");
}
break;
caseFileUtil.endDownloadMeg:
Toast.makeText(.this,
"下載完成,馬上安裝",Toast.LENGTH_SHORT).show();
/*apk安裝界面跳轉*/
Stringfilename=FileUtil.getFileName(url);
Stringstr="/myfile/"+filename;
StringfileName=Environment.getExternalStorageDirectory()+str;
Intentintent=newIntent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(newFile(fileName)),
"application/vnd.android.package-archive");
startActivity(intent);
break;
}
super.handleMessage(msg);
}
};
}
///開始下載軟體
publicvoidstartDownLoad(Viewview){
if(TextUtils.isEmpty(editText.getText().toString())){
Toast.makeText(this,"你輸入下載文件地址",Toast.LENGTH_SHORT).show();
return;
}else{
url=editText.getText().toString();
}
//啟動線程初始化下載參數
mUpdateUIThread=newUpdateUIThread(handler,url,
FileUtil.setMkdir(this)+File.separator,FileUtil.getFileName(url));
pb=newProgressDialog(this);
pb.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pb.show();
mUpdateUIThread.start();
}
}

例子代碼太長,只能給你一部分,如果想看完整例子代碼,請去360手機助手下載安卓學習手冊,點擊裡面的源碼可以查看完成代碼,方面快速,裡面還有安卓的其它小例子,共108個。

㈡ 安卓手機如何下載網頁圖片

方法一:長按圖片,接著會伴隨震動而彈出一個窗口目錄提示,裡面一般會有一個「保存」(或者「下載」按鈕)的選項,選擇即可。

方法二:點擊你 瀏覽器 的主菜單里會出現個圖片模式那附近里有一個也可以保存圖片的。保存在那個相應的文件夾也就是下載下來了。有的圖片可下載的話,就直接在網頁上就有提供下載。

㈢ android開發如何執行下載圖片到指定目錄里,然後通過imageview去讀取該圖片。

1、首先你有一個保存圖片的路徑 filePath

還有一個現在圖片的鏈接 url

StringfilePath="....";
Stringurl="....";
bytes[]b=newbytes[1024];
Filefile=newFile(filePath);
FileOutputStreamfs=newFileOutputStream(file);
InputStreamin=newURL(url);
while(in.read(b)){
fs.wirte(b);
}
Bitmapbitmap=BitmmapFactory.decodeStream(in);
imageView.setBitmapResource()

大概就是這樣詳細的你自己弄吧

閱讀全文

與android下載圖相關的資料

熱點內容
起亞k2兩廂空調壓縮機 瀏覽:998
如何操作滴滴app 瀏覽:261
華為雲服務不提供雲伺服器嗎 瀏覽:854
程序員那麼可愛1到24集 瀏覽:88
單片機報警器電路 瀏覽:67
工程圖加密費用 瀏覽:361
海上慧生活APP怎麼注銷 瀏覽:760
mac網頁里為什麼搜不到文件夾 瀏覽:14
愛奇藝會員為什麼蘋果比安卓貴 瀏覽:849
手機怎麼下載登錄寶可夢伺服器 瀏覽:541
分期樂java 瀏覽:121
30零基礎能當程序員么 瀏覽:551
蘇寧新程序員 瀏覽:795
u盤安裝linux工具 瀏覽:714
國外找住宿用什麼app 瀏覽:881
拉姆達編程 瀏覽:411
vc編程規范 瀏覽:999
安卓手機軟體加密app中文 瀏覽:124
螺紋零件加工編程 瀏覽:322
sns開源java 瀏覽:412