为android分享图片

时间:2011-09-19 06:26:24

标签: 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"));

1 个答案:

答案 0 :(得分:0)

这是从sdcard检索图像并通过电子邮件发送的代码。使用下面的链接发送带图像的邮件....希望对你有用。

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/