在Android中使用Intent将图片共享到另一个应用 [英] Share image to another app using Intent in android

查看:190
本文介绍了在Android中使用Intent将图片共享到另一个应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想与其他应用共享图像和文本,但是使用此代码时我不支持文件格式,请帮忙...

I want to share image and text to another app but i'm getting file format not supported when i'm using this code please help...

 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...."));

推荐答案

尝试一下

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..."));

这篇关于在Android中使用Intent将图片共享到另一个应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆