當前位置:首頁 » 安卓系統 » 安卓外部資源怎麼下載

安卓外部資源怎麼下載

發布時間: 2024-03-29 04:01:17

① 安卓如何實現輸入url通過url將網路資源下載並儲存到本地(無論什麼文件類型都可以下載)

主要代碼
package com.android.xiong.urltest;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {
ImageView show;
Bitmap bitmap;
Handler handler = new Handler() {

@Override
public void handleMessage(Message msg) {
if (msg.what == 0x123) {
// 使用ImageView顯示該圖片
show.setImageBitmap(bitmap);

}
}

};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
show = (ImageView) findViewById(R.id.show);

new Thread() {

@Override
public void run() {
// 定義一個URL對象
URL url;
try {
url = new URL(
圖片);
// 打開該URL的資源輸入流
InputStream is = url.openStream();
// 從InputStream中解析出圖片
bitmap = BitmapFactory.decodeStream(is);
// 發送消息
handler.sendEmptyMessage(0x123);
is.close();
// 再次打開RL對應的資源輸入流
is = url.openStream();
// 打開手機文件對應的輸出流
OutputStream os = openFileOutput("KEQIANG.JPG", MODE_APPEND);
byte[] buff = new byte[1024];
int hasRead = 0;
// 將URL資源下載到本地
while ((hasRead = is.read(buff)) > 0) {
os.write(buff, 0, hasRead);
}
is.close();
os.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}.start();
}

@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;
}

}

[html] view plain
<LinearLayout xmlns:android=網址
xmlns:tools=網址
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/show"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/hello_world"/>

</LinearLayout>

[html] view plain
</pre><pre code_snippet_id="86820" snippet_file_name="blog_20131128_4_1113442" name="code" class="html"> <uses-permission
android:name="android.permission.INTERNET"/>

② 手機安卓系統怎麼下載APP

在手機自帶的安卓市場、安智市場、應用商店搜索想下載的APP,點擊下載即可;
辦理5G快人一步,流量比4G便宜一半,寬頻提速500M,登錄廣西電信網上營業廳一鍵辦理寬頻、號卡、流量包等,方便快捷。客服156號為你解答。

③ 我想問一下安卓手機如何下載國外手機的應用

首先你要有V P N, 然後你需要使用海外版系統(因為有內置Google Play), 或者在國內版安卓手機安裝GMS. 不要用v p n瀏覽那些違法的哈

熱點內容
存儲包下行流量包 發布:2025-07-02 09:49:00 瀏覽:362
固態主控演算法 發布:2025-07-02 09:38:27 瀏覽:11
計算機存儲器尺寸是多少 發布:2025-07-02 09:32:15 瀏覽:145
危化品停車場消防器材如何配置 發布:2025-07-02 09:31:37 瀏覽:813
為什麼蘋果連安卓的熱點用這么快 發布:2025-07-02 09:31:30 瀏覽:87
easyui顯示資料庫數據 發布:2025-07-02 09:30:51 瀏覽:238
櫻花計劃腳本 發布:2025-07-02 09:30:50 瀏覽:868
計算機多層存儲系統的主要組成 發布:2025-07-02 09:26:25 瀏覽:541
同等配置的聯想和戴爾哪個更好 發布:2025-07-02 09:02:33 瀏覽:125
華為如何查詢以前設置過的密碼 發布:2025-07-02 09:02:28 瀏覽:183