使用电子邮件时共享失败

时间:2014-02-08 06:52:30

标签: android

我是Android新手。当我尝试共享从网址下载的图片时,我设法通过WhatsApp分享,但无法通过电子邮件,Gmail,消息等分享。

我的代码如下。任何人都可以看到任何问题吗?

class RetreiveFeedTaskshare extends AsyncTask<String, Void, URL> {
    @Override
    protected void onPostExecute(URL result) {
        // TODO Auto-generated method stub
        final String saveAs = "/sdcard/Funny Pics/"+ fileName; 
        Uri contentUri = Uri.fromFile(new File(saveAs)); 
        Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,contentUri); 
        getApplicationContext().sendBroadcast(mediaScanIntent); Uri uri = mediaScanIntent.getData(); 
        String path = uri.getPath(); 
        String externalStoragePath = Environment.getExternalStorageDirectory().getPath();
        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
     sharingIntent.setType("image/jpeg");
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));Log.i("test"," "+path);
    try {
        startActivity(Intent.createChooser(sharingIntent, "Share photo"));
    } catch (Exception e) {
         Log.i("test"," "+e);        }                  
    super.onPostExecute(result);
    }
    protected URL doInBackground(String... urls) {          
        for (String url : urls) {
            Bitmap bitmap = null;
            BitmapFactory.Options bmOptions = new BitmapFactory.Options();
            bmOptions.inSampleSize = 1;                    
            try {
                bitmap = BitmapFactory
                        .decodeStream(new
                        URL(url).openStream(),
                        null, bmOptions);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } try { 
                if(!imagesFolder.exists())
                    imagesFolder.mkdirs();
                int imageNum;
                if(imagesFolder.list()==null)
                    imageNum = 1;
                else
                    imageNum = imagesFolder.list().length + 1;
                fileName = "Funny" + String.valueOf(imageNum) + ".jpg";Log.i("test"," "+fileName);
                File output = new File(imagesFolder, fileName);
                while(output.exists()){
                    imageNum++;
                    fileName = "Funny" + String.valueOf(imageNum) + ".jpg";Log.i("test"," "+fileName);
                    output = new File(imagesFolder, fileName);
                }
                OutputStream fOut = new FileOutputStream(output);
                bitmap.compress(Bitmap.CompressFormat.PNG,50, fOut);
                fOut.flush();
                fOut.close();

               } catch (FileNotFoundException e) {
                e.printStackTrace();
               } catch (IOException e) {
                e.printStackTrace();
               } }
        return null;
    }
}

0 个答案:

没有答案