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

安卓外部資源怎麼下載

發布時間: 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瀏覽那些違法的哈

熱點內容
星瑞時空星辰減少了哪些配置 發布:2024-04-27 18:31:31 瀏覽:225
bat腳本錯誤碼255 發布:2024-04-27 18:20:35 瀏覽:411
華維848集團交換機如何配置 發布:2024-04-27 18:19:54 瀏覽:823
pos介面php 發布:2024-04-27 18:05:06 瀏覽:996
微信限額上傳 發布:2024-04-27 17:55:18 瀏覽:778
支持編譯成機器碼的語言 發布:2024-04-27 17:31:59 瀏覽:746
串口伺服器ip限制 發布:2024-04-27 17:30:20 瀏覽:502
sql編程入門經典 發布:2024-04-27 17:28:52 瀏覽:283
紅木卧室有哪些配置 發布:2024-04-27 17:09:47 瀏覽:856
中心機編程 發布:2024-04-27 17:00:11 瀏覽:117