2011-09-19 208 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链接?我用它可以发送带有附加图像和数据的邮件。 –