當前位置:首頁 » 安卓系統 » android圖片url

android圖片url

發布時間: 2023-01-08 02:59:29

⑴ android中怎麼跳轉到相冊獲取照片並得到url

方法/步驟
1
如下圖所示,需要根據URL地址獲取圖片載入到圖中Anroid機器人所在的位置,這是運行前的效果:

2
首先需根據URL地址獲取圖片,如下所示,urladdr即為圖片地址,返回Drawable對象:
//download image from network using @urladdress
private Drawable loadImageFromNetwork(String urladdr) {
// TODO Auto-generated method stub
Drawable drawable = null;
try{
//judge if has picture locate or not according to filename
drawable = Drawable.createFromStream(new URL(urladdr).openStream(), "image.jpg");
}catch(IOException e){
Log.d("test",e.getMessage());
}
if(drawable == null){
Log.d("test","null drawable");
}else{
Log.d("test","not null drawable");
}
return drawable;
}
3
獲取到圖片後,需要更新主線程UI資源,考慮到時間以及界面反應延遲等,所以採用線程加以處理,如下圖所示:
// image
new Thread(new Runnable(){
Drawable drawable = loadImageFromNetwork(urladdress);
@Override
public void run(){
//post() is quite important,update pictures in UI main thread
image.post(new Runnable(){
@Override
public void run(){
//TODO Auto-generated method stub
image.setImageDrawable(drawable);
}
});
}

//download image from network using @urladdress
private Drawable loadImageFromNetwork(String urladdr) {
//... 略(如 1 中所示)
}
}).start(); //線程啟動
4
說明:在上述示例代碼中,image是ImageView類的一個對象,也就是APP中的一個顯示圖像組件,利用獲取到的圖片drawable去更新image,運行效果如下所示:

⑵ Android如何獲取網路圖片

android中獲取網路圖片是一件耗時的操作,如果直接獲取有可能會出現應用程序無響應(ANR:Application Not Responding)對話框的情況。對於這種情況,一般的方法就是耗時操作用線程來實現。下面列三種獲取url圖片的方法:


  1. 直接獲取:(容易:ANR,不建議)

java">mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
mImageView.setImageDrawable(drawable);

2. 後台線程獲取url圖片:

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newThread(newRunnable(){
Drawabledrawable=loadImageFromNetwork(IMAGE_URL);
@Override
publicvoidrun(){

//post()特別關鍵,就是到UI主線程去更新圖片
mImageView.post(newRunnable(){
@Override
publicvoidrun(){
//TODOAuto-generatedmethodstub
mImageView.setImageDrawable(drawable);
}});
}

}).start();

3.AsyncTask獲取url圖片

mImageView=(ImageView)this.findViewById(R.id.imageThreadConcept);
newDownloadImageTask().execute(IMAGE_URL);
<String,Void,Drawable>
{

(String...urls){
returnloadImageFromNetwork(urls[0]);
}
protectedvoidonPostExecute(Drawableresult){
mImageView.setImageDrawable(result);
}
}

⑶ android怎麼從sd卡指定的文件夾中獲取所有圖片的路徑URL,謝謝~感謝各位大神了

直接調用文件管理器選擇圖片即可。
1、調用系統提供的圖片選擇器,代碼如下:
//注意,在Android4.4系統下建議使用 Intent.ACTION_OPEN_DOCUMENT方式
if (Utility.isKK()) {

Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image
public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {

Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column

};
處理返回結果:
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PIC_RESULT://選擇圖庫
case PIC_RESULT_KK:
imageFileUri = intent.getData();//獲取選擇圖片的URI
break;


2、除此自外,系統還提供一種選擇器,這個圖片選擇器可以屏蔽掉那個auto backup的目錄.所以就開始打算用這個圖片選擇器來選圖片了.
Intent intent=new Intent(Intent.ACTION_GET_CONTENT);//ACTION_OPEN_DOCUMENT
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/jpeg");
if(android.os.Build.VERSION.SDK_INT>=android.os.Build.VERSION_CODES.KITKAT){
startActivityForResult(intent, SELECT_PIC_KITKAT);
}else{
startActivityForResult(intent, SELECT_PIC);
}
為什麼要分開不同版本呢?其實在4.3或以下可以直接用ACTION_GET_CONTENT的,在4.4或以上,官方建議用ACTION_OPEN_DOCUMENT,主要區別是他們返回的Uri.4.3返回的是帶文件路徑的,而4.4返回的卻是content://com.android.providers.media.documents/document/image:3951這樣的,沒有路徑,只有圖片編號的uri.可以通過以下方式,處理URI。
參考:Android 4.4從圖庫選擇圖片,獲取圖片路徑並裁剪
public static String getPath(final Context context, final Uri uri) {

final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
// DocumentProvider
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
// ExternalStorageProvider
if (isExternalStorageDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];

if ("primary".equalsIgnoreCase(type)) {
return Environment.getExternalStorageDirectory() + "/" + split[1];
}

// TODO handle non-primary volumes
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {

final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

return getDataColumn(context, contentUri, null, null);
}
// MediaProvider
else if (isMediaDocument(uri)) {
final String docId = DocumentsContract.getDocumentId(uri);
final String[] split = docId.split(":");
final String type = split[0];

Uri contentUri = null;
if ("image".equals(type)) {
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else if ("video".equals(type)) {
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
} else if ("audio".equals(type)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}

final String selection = "_id=?";
final String[] selectionArgs = new String[] {
split[1]
};

return getDataColumn(context, contentUri, selection, selectionArgs);
}
}
// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {

// Return the remote address
if (isGooglePhotosUri(uri))
return uri.getLastPathSegment();

return getDataColumn(context, uri, null, null);
}
// File
else if ("file".equalsIgnoreCase(uri.getScheme())) {
return uri.getPath();
}

return null;
}

public static String getDataColumn(Context context, Uri uri, String selection,
String[] selectionArgs) {

Cursor cursor = null;
final String column = "_data";
final String[] projection = {
column
};

try {
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}

public static boolean isExternalStorageDocument(Uri uri) {
return "com.android.externalstorage.documents".equals(uri.getAuthority());
}

public static boolean isDownloadsDocument(Uri uri) {
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}

public static boolean isMediaDocument(Uri uri) {
return "com.android.providers.media.documents".equals(uri.getAuthority());
}

public static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}

3、使用其它開源組件如PhotoView。

⑷ android怎麼載入一個有圖片的url

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("img");

⑸ Android中的imageview控制項 怎麼設置url 網路上的圖片呢在網上找了很多方法都不行,都會報什麼網路

Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);
這個試過沒有

⑹ android 從json中解析出了所需圖片的url(String)。

imageloader載入網路圖片或者volley的metworkimageview載入網路圖片

⑺ android本地mipmap圖片轉url、絕對路徑轉URL

(一)mipmap圖片轉url,參數 resId為 直接傳入R.mipmap.img

(二)絕對路徑轉URL。 it.compressPath為本地圖片的絕對路徑

⑻ android:URL網路下載圖片問題,,源代碼已經有許可權了 電腦也有網路為啥就是在ImageView中顯示不出來呢

因為你獲取圖片的時候訪問網路了
而android4.0之後 訪問網路智能在非主線程中使用,,
難道你這么寫沒報錯嗎?

安卓手機如何打開.url文件

安卓手機打開.url文件首先需要在文件管理器中找到需要打開的url文件,再用文本方式打開,點擊使用HTML查看器打開。最底下一行是網路地址,從=號後面開始選擇,直接復制,打開瀏覽器在瀏覽器搜索欄中粘貼url,點擊進入即可看到相關內容。

安卓手機打開.url文件需要一個帶有瀏覽器以及正常上網能力的手機,打開方式如下:

1、在文件管理器中找到需要打開的url文件,並選擇打開方式為文本。

2、用文本方式打開後,會彈出查看工具,點擊使用HTML查看器打開。

3、最底下一行是網路地址,從=號後面開始選擇,直接復制。

4、打開瀏覽器在瀏覽器搜索欄中粘貼url,點擊進入

URL:統一資源定位符是對可以從互聯網上得到的資源的位置和訪問方法的一種簡潔的表示,是互聯網上標准資源的地址。互聯網上的每個文件都有一個唯一的URL,它包含的信息指出文件的位置以及瀏覽器應該怎麼處理它。

⑽ android根據url獲取網路圖片報錯

這個看著是https協議的URL,用普通的http請求就報錯了,我這里只有請求https到流的代碼,給你先看看,把流再轉成文件 就可以了


@SuppressLint("ParserError")
(StringdownUrl,StringpostStr)throwsIOException{
Stringres="";

HttpsURLConnection.setDefaultHostnameVerifier(newNullHostNameVerifier());
SSLContextcontext=null;
try{
context=SSLContext.getInstance("TLS");
}catch(NoSuchAlgorithmExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}

try{
context.init(null,newX509TrustManager[]{newmyX509TrustManager()},newSecureRandom());
}catch(KeyManagementExceptione1){
//TODOAuto-generatedcatchblock
e1.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());

URLdUrl=newURL(downUrl);
HttpsURLConnectiondConn=(HttpsURLConnection)dUrl.openConnection();

dConn.setDoInput(true);
if(postStr!=""){
dConn.setDoOutput(true);
dConn.setRequestMethod("POST");
}

dConn.connect();

if(postStr!=""){
try{
BufferedWriterout=newBufferedWriter(newOutputStreamWriter(
dConn.getOutputStream()));
out.write(postStr);
out.flush();

}catch(Exceptione){
StringerrMsg=e.getMessage();
if(null!=errMsg){
Toasttoast=Toast.makeText(null,errMsg,Toast.LENGTH_LONG);
toast.show();
}

e.printStackTrace();
}

}


BufferedInputStreamin=newBufferedInputStream(dConn.getInputStream());

returnin;
}


{
@Override
publicbooleanverify(Stringhostname,SSLSessionsession){
//Log.i("RestUtilImpl","Approvingcertificatefor"+hostname);
returntrue;
}
}

{
@Override
publicX509Certificate[]getAcceptedIssuers(){
returnnull;
}

@Override
publicvoidcheckClientTrusted(X509Certificate[]chain,StringauthType)
throwsCertificateException{
//TODOAuto-generatedmethodstub
}

@Override
publicvoidcheckServerTrusted(X509Certificate[]chain,StringauthType)
throwsCertificateException{
//TODOAuto-generatedmethodstub
}
}
熱點內容
android360源碼 發布:2025-05-17 09:11:47 瀏覽:76
步科編程軟體 發布:2025-05-17 09:09:18 瀏覽:824
ps4密碼設置有什麼要求 發布:2025-05-17 08:49:16 瀏覽:70
文本編譯工具 發布:2025-05-17 08:47:47 瀏覽:3
phpc語言 發布:2025-05-17 08:45:30 瀏覽:806
蘋果6s怎麼設置4位密碼 發布:2025-05-17 08:41:14 瀏覽:180
如何玩cf端游越南伺服器 發布:2025-05-17 08:38:54 瀏覽:184
雜訊的危害和控制設計腳本 發布:2025-05-17 08:22:29 瀏覽:474
esr演算法 發布:2025-05-17 08:16:09 瀏覽:195
安卓手機怎麼用擬我表情 發布:2025-05-17 08:10:13 瀏覽:919