2011-09-19 97 views
0

嗨,我想分享圖像郵件,臉譜等。我可以分享文字到社交媒體,但即時通訊不能共享圖像。我該如何分享我的形象?我的代碼如下:Android的共享圖像

Intent sharingIntent = new Intent(Intent.ACTION_SEND); 
Uri screenshotUri = Uri.parse("http://www.golfcourseranking.com/pics/1419630512.jpg"); 

sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);sharingIntent.setType("image/jpeg"); 
startActivity(Intent.createChooser(sharingIntent, "Share image using")); 

回答

0

這裏是從SD卡中檢索圖像並通過電子郵件發送的代碼。使用下面的鏈接發送圖像的郵件....希望對你有用。

http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android

Intent intent = new Intent(); 
        intent.setType("image/*"); 
        intent.setAction(Intent.ACTION_GET_CONTENT); 
        **startActivityForResult**(Intent.createChooser(intent,"Select Picture"), SELECT_PICTURE); 

protected final void onActivityResult(int requestCode, int 
      resultCode, final Intent i) { 
      super.onActivityResult(requestCode, resultCode, i);   
      if(resultCode == RESULT_OK){ 
       // this matches the request code in the above call 
       if (requestCode == 1) { 
        Uri _uri = i.getData(); 

        // this will be null if no image was selected... 
        if (_uri != null) { 
//      now we get the path to the image file 
         Cursor cursor = getContentResolver().query(_uri, null, 
          null, null, null); 
         cursor.moveToFirst(); 
         int x=cursor.getInt(0); 
//      txtview.setText(imageFilePath); 
         int columnIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);         
        // Get image filename 
         imagePath = cursor.getString(columnIndex); 
         Log.d("Full Path",""+imagePath); 
         Toast.makeText(BrowsePicture.this, ""+imagePath, Toast.LENGTH_LONG).show(); 
         File rootsd = Environment.getExternalStorageDirectory(); 
         Log.d("abpath",""+rootsd.getAbsolutePath()); 

         f= new File(imagePath); 
         Log.d("filename", f.getName()); 

//      iv.setImageURI(Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,""+ x)); 
         iv.setImageURI(Uri.parse(imagePath)); 
         cursor.close(); 

         // here is the code sending mail 

//      **sendmail**(imagePath,f.getName()); 
         progressDialog = ProgressDialog.show(this, "Please Wait...", "Sending Mail...",true); 

         thread = new Runnable() { 
          public void run() {        
           Log.d("Photo Image", "in thread"); 
//        Toast.makeText(BrowsePicture.this, "in thread", Toast.LENGTH_SHORT).show(); 
           sendmail(imagePath,f.getName()); 
          } 
         }; 
         t= new Thread(null, thread, "sending photo"); 
         t.start(); 
        } 
       } 
      } 
    } 

或路

http://davanum.wordpress.com/2007/12/22/android-send-email-via-gmail-actually-via-smtp/

+0

感謝您的答覆。但我不想從服務器上獲取圖像。我必須動態檢索圖像,並且我想分享它們。我在郵件中獲得了圖像名稱,但附件是使用android TF101設備的failed.im。如何解決這個問題? – gowri

+0

沒有從服務器獲取圖像,但它從SD卡(本地存儲卡)... –

+0

你有使用庫中可用http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android鏈接?我用它可以發送帶有附加圖像和數據的郵件。 –