在Android中使用Intent将图像分享到另一个应用程序

问题描述 投票:1回答:2

我想将图像和文本分享给另一个应用程序,但是当我使用此代码时,我的文件格式不受支持请帮助...

 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...."));
android share
2个回答
2
投票

试试这个

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

0
投票

The documentation for EXTRA_STREAM说,Uri需要有一个content计划。 file通常也适用,至少在Android 6.0及更早版本上。很少有应用程序会期望http URL。

© www.soinside.com 2019 - 2024. All rights reserved.