Android 如何使用位图发送到其他应用程序

Android 如何使用位图发送到其他应用程序,android,bitmap,Android,Bitmap,有人能帮我在android中如何将图像发送到另一个应用程序吗 我想发送一张图像,用作壁纸、BBM显示图片和其他可以使用它的应用程序(如WhatsApp、contacts等) 我使用这段代码,但它只能用于发送文本,而不是我想要的图像 Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to

有人能帮我在android中如何将图像发送到另一个应用程序吗

我想发送一张图像,用作壁纸、BBM显示图片和其他可以使用它的应用程序(如WhatsApp、contacts等)

我使用这段代码,但它只能用于发送文本,而不是我想要的图像

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
然后我试着用这个代码来设置壁纸

public void setAsWallpaper(Bitmap bitmap) {
        try {           
            WallpaperManager wm = WallpaperManager.getInstance(_context);
            wm.setBitmap(bitmap);

            //disinimas
            Toast.makeText(_context,
                    _context.getString(R.string.toast_wallpaper_set),
                    Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(_context,
                    _context.getString(R.string.toast_wallpaper_set_failed),
                    Toast.LENGTH_SHORT).show();
        }
    }
问题代码,位图图像直接作为壁纸应用。我想像上面发送文本一样,用户可以选择使用其他应用程序。所以我想要一个位图图像,以后可以用于墙纸、BBM显示图片或其他支持它的应用程序

位图变量已经包含我想要的图像,这些图像是通过以下代码从internet获得的:

Bitmap bitmap = ((BitmapDrawable) fullImageView.getDrawable())
                .getBitmap();
我使用此代码及其工作,但给我一个消息BBM:File not found,WhatsApp:File不是图像:

Bitmap icon = bitmap;
    Intent share = new Intent(Intent.ACTION_ATTACH_DATA);
    share.setType("image/jpeg");

    ContentValues values = new ContentValues();
    values.put(Images.Media.TITLE, "title");
    values.put(Images.Media.MIME_TYPE, "image/jpeg");
    Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
            values);


    OutputStream outstream;
    try {
        outstream = getContentResolver().openOutputStream(uri);
        icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
        outstream.close();
    } catch (Exception e) {
        System.err.println(e.toString());
    }

    share.putExtra(Intent.EXTRA_STREAM, uri);
    startActivity(Intent.createChooser(share, "Share Image"));

您是否尝试使用以下代码?它可以用于其他应用程序

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
或者,如果您没有URI,但是有位图,那么请尝试使用给定的代码

更新:

为BBM设置壁纸和个人资料图片是完全不同的事情,它们没有共同的意图。要设置墙纸,您可以尝试以下方法


对于BBM,API不能用于更改用户映像。所以你不能通过你的应用程序做到这一点。

谢谢你的帮助Antromet,最后我用以下代码解决了我的问题:

Bitmap icon = bitmap;
        //  Intent share = new Intent(Intent.ACTION_SEND);
        //  share.setType("image/*");

            ContentValues values = new ContentValues();
            values.put(Images.Media.TITLE, "title");
            values.put(Images.Media.MIME_TYPE, "image/*");
            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
                    values);


            OutputStream outstream;
            try {
                outstream = getContentResolver().openOutputStream(uri);
                icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
                outstream.close();
            } catch (Exception e) {
                System.err.println(e.toString());
            }

            Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setDataAndType(uri, "image/*");
            intent.putExtra("mimeType", "image/*");
            this.startActivity(Intent.createChooser(intent, "Set as:"));

现在图像可以用作墙纸、BBM配置文件图片、WA显示图片、接触显示图片等。谢谢

我有位图,我尝试此链接。我的意思是,我想发送一个位图,可以制作成墙纸、BBM显示图片、WhatsApp显示图片等。使用链接中的代码可以共享图片,而不是按照我的要求将其设置为墙纸或BBM显示图片。我收到以下消息:BBM:未找到文件,WhatsApp:文件不是图像,请参阅我的问题,我正在更新它
Bitmap icon = bitmap;
        //  Intent share = new Intent(Intent.ACTION_SEND);
        //  share.setType("image/*");

            ContentValues values = new ContentValues();
            values.put(Images.Media.TITLE, "title");
            values.put(Images.Media.MIME_TYPE, "image/*");
            Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
                    values);


            OutputStream outstream;
            try {
                outstream = getContentResolver().openOutputStream(uri);
                icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
                outstream.close();
            } catch (Exception e) {
                System.err.println(e.toString());
            }

            Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setDataAndType(uri, "image/*");
            intent.putExtra("mimeType", "image/*");
            this.startActivity(Intent.createChooser(intent, "Set as:"));