2015-11-13 63 views
-3

我創建了一個用於從Web瀏覽器共享內容的android應用程序。我用意圖從Web瀏覽器接收數據。它只給我文本/純文本(僅url)數據。如何在接收頁面中顯示文章圖像和文字?如何從android中提取圖片和文本url

+0

請添加您的代碼,以便人們可以幫助您 –

+3

從url下載它?你在找什麼? – Nanoc

+0

是@Nanco。我現在正在獲取網址。我如何才能簡要顯示頁面的內容以便共享。 –

回答

0

獲取隱式意圖數據後,只需運行異步任務,或者您可以使用Volley庫從URL加載數據。看到這個例子,

//Implicit Intent Data onActivityResult 

    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
         // TODO Auto-generated method stub 
     super.onActivityResult(requestCode, resultCode, data); 
     String url = data.getData().toString(); 

     RequestQueue queue = Volley.newRequestQueue(this); 

     // Request a string response from the provided URL. 
     StringRequest stringRequest = new StringRequest(Request.Method.GET, url, 
        new Response.Listener<String>() { 
      @Override 
      public void onResponse(String response) { 
       // Display the first 500 characters of the response string. 
       mTextView.setText("Response is: "+ response.substring(0,500)); 
      } 
     }, new Response.ErrorListener() { 
      @Override 
      public void onErrorResponse(VolleyError error) { 
       mTextView.setText("That didn't work!"); 
      } 
     }); 
     // Add the request to the RequestQueue. 
     queue.add(stringRequest); 


    // Retrieves an image specified by the URL, displays it in the UI. 
    ImageRequest request = new ImageRequest(url, 
     new Response.Listener<Bitmap>() { 
      @Override 
      public void onResponse(Bitmap bitmap) { 
       mImageView.setImageBitmap(bitmap); 
      } 
     }, 0, 0, null, 
     new Response.ErrorListener() { 
      public void onErrorResponse(VolleyError error) { 
       mImageView.setImageResource(R.drawable.image_load_error); 
      } 
     }); 
       queue.add(request); 
        }