2017-08-04 54 views
1

我想分享圖片和文字到另一個應用程序,但我發現,當我使用此代碼,請幫助文件格式不支持其他應用程序...分享圖像使用意圖在android系統

Uri picUri = Uri.parse("http://www.planwallpaper.com/static/images/image-slider-2.jpg"); 
      Intent shareIntent = new Intent(); 
      shareIntent.setAction(android.content.Intent.ACTION_SEND); 
      shareIntent.putExtra(Intent.EXTRA_TEXT, "Hi There..."); 
      shareIntent.putExtra(android.content.Intent.EXTRA_STREAM, picUri); 
      shareIntent.setType("*/*"); 
      startActivity(Intent.createChooser(shareIntent, "Share Image....")); 
+0

爲什麼不分享URI作爲一個字符串? –

+0

我試過它不起作用@Nilesh發佈的波紋管代碼作品 –

回答

2

試試這個

private class myTask extends AsyncTask<Void, Void, Bitmap> { 


    protected Bitmap doInBackground(Void... params) { 
     Bitmap myBitmap=null; 
     try { 
      URL url = new URL(src); 
      HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
      connection.setDoInput(true); 
      connection.connect(); 
      InputStream input = connection.getInputStream(); 
      myBitmap = BitmapFactory.decodeStream(input); 

     } catch (IOException e) { 
      // Log exception 
     } 
     return myBitmap; 
    } 

    @Override 
    protected void onPostExecute(Bitmap result) { 
     //do stuff 

    } 
} 

Bitmap returned_bitmap = new myTask().execute().get() 



Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra(Intent.EXTRA_TEXT, "download this image"); 
String bitmapPath = Images.Media.insertImage(getContentResolver(), returned_bitmap,"title", null); 
Uri bitmapUri = Uri.parse(bitmapPath);  
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri); 
intent.setType("image/*"); 
startActivity(Intent.createChooser(intent, "Share image via...")); 
+0

當我使用您發送的第一個代碼時,我收到文件未找到異常.... –

+0

java.io.FileNotFoundException:http: /www.planwallpaper.com/static/images/image-slider-2.jpg:打開失敗:ENOENT(沒有這樣的文件或目錄) –

+0

你想發送圖像url或圖像到其他應用程序 –